using Common.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Configuration; using DSWeb.Areas.Dispatch.Helper; using Newtonsoft.Json; using System.Runtime.Caching; using System.Text; using System.IO; using DSWeb.Areas.Dispatch.DB; using DSWeb.Areas.Dispatch.DB_Wx; using DSWeb.Areas.CommMng.DAL; using HcUtility.Comm; namespace DSWeb.Areas.Dispatch.Controllers { public class repobj { public string openid { get; set; } public int errcode { get; set; } } public class LoginInfo { public string codename { get; set; } public string password { get; set; } public string AuthCode { get; set; } } //微信小程序专用接口控制器 public class WxAppController : Controller { private ILog log = LogManager.GetLogger("WxAppController"); private WxAppDataContext dbc = new WxAppDataContext(); private string filepath = ConfigurationManager.AppSettings["DSWMSFilePath"]; /// /// /// private repobj getOpenId(string code) { var appid = ConfigurationManager.AppSettings["WechatAppId"]; var appsecret = ConfigurationManager.AppSettings["WechatAppSecret"]; var url = $"https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={appsecret}&js_code={code}&grant_type=authorization_code"; log.Debug("获取openid:" + url); string resp = WebRequestHelper.DoGet(url); repobj result = JsonConvert.DeserializeAnonymousType(resp, new repobj { openid = "", errcode = 0 }); log.Debug("返回:" + resp); return result; } public String getDataStr(DateTime? dt) { return dt == null ? "" : ((DateTime)dt).ToString("yyyy-MM-dd"); } public String getDataLongStr(DateTime? dt) { return dt == null ? "" : ((DateTime)dt).ToString("yyyy-MM-dd HH:mm:ss"); } //#region 裕龙集团用小程序 //校验用户是否存在,并获取用户信息 [HttpGet] public ActionResult GetUserInfo(string code) { try { var obj = getOpenId(code); //BasicDataRefDAL.SaveLog("获得openid", obj.openid, "wxapp", "获取用户信息"); var userWx = dbc.Users.FirstOrDefault(x => x.OPENID == obj.openid); if (userWx != null) { var userinfo = dbc.vw_user.First(x => x.USERID == userWx.GID); //BasicDataRefDAL.SaveLog("", "", "wxapp", "获取用户信息1"); return Json(new { ErrorCode = 0, Message = "获取成功", BaseInfo = new { userinfo.SHOWNAME, userWx.CODENAME, userinfo.companyname, userWx.OPENID, userinfo.Role_Id , userinfo.COMPANYID, userinfo.USERID } }, JsonRequestBehavior.AllowGet); } else { //BasicDataRefDAL.SaveLog("", "", "wxapp", "获取用户信息2"); return Json(new { ErrorCode = -1, Message = "用户不存在" }, JsonRequestBehavior.AllowGet); } //BasicDataRefDAL.SaveLog("", "", "wxapp", "获取用户信息3"); return Json(new { ErrorCode = 500, Message = "发生错误" }, JsonRequestBehavior.AllowGet); } catch (Exception e) { //log.Debug("获取信息错误" + e.Message); //BasicDataRefDAL.SaveLog("错误", e.Message, "wxapp", "获取用户信息"); return Json(new { ErrorCode = 500, Message = e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 用户登陆 使用系统用户名和密码登陆 /// /// /// [HttpPost] public ActionResult FirstLogin(LoginInfo logininfo) { var obj = getOpenId(logininfo.AuthCode); BasicDataRefDAL.SaveLog("获得openid", obj.openid, "wxapp", "登录"); try { if (obj.errcode == 0) { BasicDataRefDAL.SaveLog("", obj.openid, "wxapp", "登录1"); var userWxList = dbc.Users.Where(x => x.OPENID == obj.openid).ToList(); if (userWxList.Count > 0) { //将所有使用这个openid的user数据的openid置为‘’ 然后继续正常操作 foreach (var item in userWxList) { item.OPENID = ""; } } BasicDataRefDAL.SaveLog($"codename[{logininfo.codename}],password[{logininfo.password}]", obj.openid, "wxapp", "登录2"); //将正确的用户名和密码的那条user数据 的openid修改为传入的 var userWx = dbc.Users.FirstOrDefault(x => x.CODENAME.ToUpper() == logininfo.codename.ToUpper() && x.PASSWORD == logininfo.password); if (userWx != null) { userWx.OPENID = obj.openid; dbc.SaveChanges(); } else { BasicDataRefDAL.SaveLog("用户名、密码错误", obj.openid, "wxapp", "登录2.1"); } var userinfo = dbc.vw_user.First(x => x.USERID == userWx.GID); BasicDataRefDAL.SaveLog("", obj.openid, "wxapp", "登录3"); return Json(new { ErrorCode = 0, Message = "获取成功", BaseInfo = new { userinfo.SHOWNAME, userWx.CODENAME, userinfo.companyname, userWx.OPENID } }, JsonRequestBehavior.AllowGet); } } catch (Exception e) { log.Debug("wxapp登陆错误:" + e.Message); } BasicDataRefDAL.SaveLog("", obj.openid, "wxapp", "登录f"); return Json(new { ErrorCode = 500, Message = "发生错误" }, JsonRequestBehavior.AllowGet); } /// /// 获取进行中的入库执行单 /// /// /// [HttpGet] public ActionResult GetINDOList(string CODENAME) { try { var userinfo = dbc.vw_user.First(x => x.CODENAME == CODENAME); var limit = dbc.Sys_Role_Core.First(x => x.Role_Id == userinfo.Role_Id).LimitCompanyRange; var indoList = new List(); //寻找 本公司的“入库执行 1001”的入库执行单列表 if (limit) { indoList = dbc.VW_OP_WMS_IN_DO.Where(x => x.CORPID == userinfo.COMPANYID && x.BILLSTATUS == "1001" && (x.CUSTOMERNAME!=null && x.CUSTOMERNAME != "")).ToList(); } else { indoList = dbc.VW_OP_WMS_IN_DO.Where(x => x.BILLSTATUS == "1001" && (x.CUSTOMERNAME != null && x.CUSTOMERNAME != "")).ToList(); } indoList.Sort((x, y) => 4 * x.CUSTOMERNAME.CompareTo(y.CUSTOMERNAME)+2*x.MBLNO.CompareTo(y.MBLNO)); return Json(new { ErrorCode = 0, data = indoList }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:"+e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 获取入库执行明细 /// /// /// [HttpGet] public ActionResult GetINDODetailList(string WMSDOID) { try { //var userinfo = dbc.vw_user.First(x => x.CODENAME == CODENAME); //寻找 本公司的“入库执行 1001”的入库执行单列表 var indoList = dbc.VW_OP_WMS_IN_DO_GOODS.Where(x => x.WMSDOID == new Guid(WMSDOID)).ToList(); return Json(new { ErrorCode = 0, data = indoList }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 获取进行中的出库作业单列表 /// /// /// [HttpGet] public ActionResult GetOUTDOList(string CODENAME) { try { var userinfo = dbc.vw_user.First(x => x.CODENAME == CODENAME); //寻找 本公司的“出库执行 1010”的出库作业单列表 var outdoList = dbc.VW_OP_WMS_OUT_DO.Where(x => x.CORPID == userinfo.COMPANYID && (x.BILLSTATUS == "1010")).ToList(); var resultdata = outdoList.Select(x => new { WMSDOID = x.WMSDOID, WMSNO = x.WMSNO, MBLNO = x.MBLNO==null?"": x.MBLNO, CORPID = x.CORPID, CUSTOMERNAME = x.CUSTOMERNAME, DODATE = getDataStr(x.DODATE), REMARK = x.REMARK, TRUCKNO = x.TRUCKNO, CNTRNO = x.CNTRNO, }).ToList(); resultdata.Sort((x, y) => 8 * x.DODATE.CompareTo(y.DODATE) + 4 * x.CUSTOMERNAME.CompareTo(y.CUSTOMERNAME) + 2 * x.MBLNO.CompareTo(y.MBLNO) ); return Json(new { ErrorCode = 0, data = resultdata }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 获取用指定gid和指定箱号共同关联的电子文档 /// /// /// /// [HttpGet] public ActionResult GetInfoFileList(string PID,string CNTRNO) { try { var indoList = dbc.VW_INFO_FILES.Where(x => x.PID == new Guid(PID) && x.CNTRNO== CNTRNO).ToList(); var fileList = indoList.Select(x => new { GID = x.GID, CNTRNO = x.CNTRNO, IMAGES = x.IMGPATH.Split(',').ToList(), ModifyDate = getDataLongStr(x.ModifyDate) }).ToList(); var resultlist = new List(); foreach (var infofile in fileList) { var newlist = new List(); foreach (var imgpath in infofile.IMAGES) { //var _newpath = "/DSWMSPIC/" + imgpath; var _newpath = new IMG(); _newpath.IMGPATH = imgpath; newlist.Add(_newpath); } var newresultfile = new INFO_FILES_TEMP(); newresultfile.GID = infofile.GID; newresultfile.CNTRNO = infofile.CNTRNO; newresultfile.IMGPATHLIST = newlist; newresultfile.ModifyDate = infofile.ModifyDate; resultlist.Add(newresultfile); } fileList.Sort((x, y) => -x.ModifyDate.CompareTo(y.ModifyDate)); return Json(new { ErrorCode = 0, data = resultlist }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 获取全部电子文档 /// /// /// [HttpGet] public ActionResult GetInfoFileList_ALL(string ROLE_ID,string COMPANYID,string MBLNO, string CNTRNO) { try { if (string.IsNullOrWhiteSpace(MBLNO) && string.IsNullOrWhiteSpace(CNTRNO)) { return Json(new { ErrorCode = 500, Message = "发生错误:提单号和箱号至少要填写一个" }, JsonRequestBehavior.AllowGet); } if(!string.IsNullOrWhiteSpace(MBLNO) && MBLNO.Length<3) return Json(new { ErrorCode = 500, Message = "发生错误:提单号至少要填三位" }, JsonRequestBehavior.AllowGet); if (!string.IsNullOrWhiteSpace(CNTRNO) && CNTRNO.Length < 3) return Json(new { ErrorCode = 500, Message = "发生错误:箱号至少要填三位" }, JsonRequestBehavior.AllowGet); var limit = dbc.Sys_Role_Core.First(x => x.Role_Id == ROLE_ID).LimitCompanyRange; var indoList = new List(); if (limit) { //var companyuserid = dbc.vw_user.Where(x => x.COMPANYID == COMPANYID).Select(s => new Guid(s.USERID)).ToList(); indoList = dbc.VW_INFO_FILES.Where(x => x.CORPID == COMPANYID).ToList(); if (!string.IsNullOrWhiteSpace(MBLNO)) { indoList= indoList.Where(x => x.MBLNO.Contains(MBLNO)).ToList(); } if (!string.IsNullOrWhiteSpace(CNTRNO)) { indoList=indoList.Where(x => x.CNTRNO.Contains(CNTRNO)).ToList(); } } else { if (!string.IsNullOrWhiteSpace(MBLNO)) { indoList = dbc.VW_INFO_FILES.Where(x => x.MBLNO.Contains( MBLNO)).ToList(); if (!string.IsNullOrWhiteSpace(CNTRNO)) { indoList= indoList.Where(x => x.CNTRNO.Contains(CNTRNO)).ToList(); } } else if (!string.IsNullOrWhiteSpace(CNTRNO)) { indoList = dbc.VW_INFO_FILES.Where(x => x.CNTRNO.Contains(CNTRNO)).ToList(); } //indoList = dbc.VW_INFO_FILES.Where(x => (x.MBLNO.Contains(MBLNO) )).ToList(); } indoList = indoList.Where(x => x.IMGPATH != null && x.IMGPATH != "").ToList(); var fileList = indoList.Select(x => new { GID = x.GID, PWORKTYPE = x.PWORKTYPE, MBLNO = x.MBLNO, CNTRNO = x.CNTRNO, Modifier = x.Modifier, ModifyDate = getDataLongStr(x.ModifyDate), IMAGES = x.IMGPATH.Split(',').ToList() }).ToList(); var resultlist = new List(); foreach (var infofile in fileList) { var newlist = new List(); foreach (var imgpath in infofile.IMAGES) { //var _newpath = "/DSWMSPIC/" + imgpath; var _newpath = new IMG(); _newpath.IMGPATH = imgpath; newlist.Add(_newpath); } var newresultfile = new INFO_FILES_TEMP2(); newresultfile.GID = infofile.GID; newresultfile.CNTRNO = infofile.CNTRNO == null ? "" : infofile.CNTRNO; newresultfile.MBLNO = infofile.MBLNO==null?"": infofile.MBLNO; newresultfile.PWORKTYPE = infofile.PWORKTYPE; newresultfile.IMGPATHLIST = newlist; newresultfile.ModifyDate = infofile.ModifyDate; resultlist.Add(newresultfile); } resultlist.Sort((x, y) => 4 * x.MBLNO.CompareTo(y.MBLNO) + 2 * x.CNTRNO.CompareTo(y.CNTRNO) + x.ModifyDate.CompareTo(y.ModifyDate)); return Json(new { ErrorCode = 0, data = resultlist }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 获取货物库位信息 /// /// /// [HttpGet] public ActionResult GetAREAGOODS(string ROLE_ID, string COMPANYID, string MBLNO, string CNTRNO) { try { if (string.IsNullOrWhiteSpace(MBLNO) && string.IsNullOrWhiteSpace(CNTRNO)) { return Json(new { ErrorCode = 500, Message = "发生错误:提单号和箱号至少要填写一个" }, JsonRequestBehavior.AllowGet); } if (!string.IsNullOrWhiteSpace(MBLNO) && MBLNO.Length < 3) return Json(new { ErrorCode = 500, Message = "发生错误:提单号至少要填三位" }, JsonRequestBehavior.AllowGet); if (!string.IsNullOrWhiteSpace(CNTRNO) && CNTRNO.Length < 3) return Json(new { ErrorCode = 500, Message = "发生错误:箱号至少要填三位" }, JsonRequestBehavior.AllowGet); var limit = dbc.Sys_Role_Core.First(x => x.Role_Id == ROLE_ID).LimitCompanyRange; var resultList = new List(); if (!string.IsNullOrWhiteSpace(MBLNO)) { resultList = dbc.VW_OP_WMS_AREAGOODS.Where(x => x.MBLNO.Contains(MBLNO)).ToList(); if (!string.IsNullOrWhiteSpace(CNTRNO)) { resultList = resultList.Where(x => x.CNTRNO.Contains(CNTRNO)).ToList(); } } else { resultList = dbc.VW_OP_WMS_AREAGOODS.Where(x => (x.CNTRNO.Contains(CNTRNO))).ToList(); } if (limit) { resultList = resultList.Where(x => x.CORPID==COMPANYID).ToList(); } else { } if(resultList!=null) resultList.Sort((x, y) => 4 * x.MBLNO.CompareTo(y.MBLNO) + 2 * x.CNTRNO.CompareTo(y.CNTRNO) + x.AREANAME.CompareTo(y.AREANAME)); return Json(new { ErrorCode = 0, data = resultList }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } //#endregion [HttpPost] public ActionResult UploadFile() { try { if (Request.Files.Count > 0) { var pid = Request.Form["pid"].ToString().Trim(); var mblno = Request.Form["mblno"].ToString().Trim(); var cntrno = Request.Form["cntrno"].ToString().Trim(); var codename = Request.Form["codename"].ToString().Trim(); var pworktype = Request.Form["pworktype"].ToString().Trim(); var userinfo = dbc.vw_user.First(x => x.CODENAME == codename); var dayfilepath = DateTime.Today.ToString("yyyyMMdd"); var InfoFilesPath = "Upload/Tables/VW_INFO_FILES/" + dayfilepath;//保存到数据库info_files表的路径 string upDir = Path.Combine(ConfigurationManager.AppSettings["DSWMSPICPATH"], InfoFilesPath); if (!Directory.Exists(upDir)) { Directory.CreateDirectory(upDir); } //H:\DSWMS\Vue.Net\VOL.WebApi\wwwroot\Upload/Tables/VW_INFO_FILES/202012100909412467/1.jpg //新增一条电子档案info_files var newInfoFiles = new INFO_FILES(new Guid(pid), pworktype, mblno, cntrno); newInfoFiles.setuser(userinfo); for (int c = 0; c < Request.Files.Count; c++) { var uploadFile = Request.Files[c]; if (uploadFile.ContentLength == 0) { continue; } var extension = Path.GetExtension(uploadFile.FileName); var timename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + new Random().Next(100, 999) + extension; var filepath = "\\" + timename;//随机生成文件名 var infofilepath = InfoFilesPath +"/"+ timename; var savePath = upDir + filepath; uploadFile.SaveAs(savePath); if (!string.IsNullOrWhiteSpace(newInfoFiles.IMGPATH)) { newInfoFiles.IMGPATH += ","; } newInfoFiles.IMGPATH += infofilepath; //InfoFileList.Add(new { id = DateTime.Now.Ticks, url = relativepath + filepath, size = uploadFile.ContentLength }); } dbc.INFO_FILES.Add(newInfoFiles); dbc.SaveChanges(); return Json(new { Success = true, Message = "上传成功", Data = JsonConvert.SerializeObject(newInfoFiles) }); } } catch (Exception e) { return Json(new { Success = false, Message = e.Message }); } return Json(new { Success = false, Message = "没有文件" }); } /// /// 删除电子文档 /// 如果关联的入库执行没有处于1001状态,则不允许删除 /// /// [HttpGet] public ActionResult DelInfoFiles(string GID) { try { //1首先找到这条电子文档 var infofile = dbc.INFO_FILES.FirstOrDefault(x => x.GID == new Guid(GID)); if (infofile == null) return ErrorResult("没有可以删除的文件"); //2判断关联业务的状态 看能否删除 if (infofile.PWORKTYPE == "入库执行") { var indo = dbc.VW_OP_WMS_IN_DO.FirstOrDefault(x => x.WMSDOID == infofile.PID); if(indo==null) return ErrorResult("没有可以删除的文件"); if(indo.BILLSTATUS!="1001") return ErrorResult("业务完成,不可删除"); } //3执行删除 CommMng.DAL.BasicDataRefDAL.ExecSql($"delete from info_files where gid='{GID}'"); } catch (Exception e) { return ErrorResult(e.Message); } return ErrorResult("没有可以删除的文件"); } private ActionResult ErrorResult(string msg) { return Json(new { Success = false, Message = "msg" }); } /// /// 虎鲸 小程序 /// 获取该用户需要执行的业务 /// /// /// //[HttpGet] /* public ActionResult GetCTNMNGList(string USERID) { try { var resultList = new List(); var cdc = new CommonDataContext(); var wx = new WxAppDataContext(); //寻找这个人需要执行的业务内容 //寻找OP_YARD_CTNMNG_WORK当中OP=这个人 ,且WORKSTATUS为空或为未处理的 //将这些OP_YARD_CTNMNG_WORK的父节点返回 //var _user = cdc.Users.FirstOrDefault(x => x.CODENAME == CODENAME); var detailList = wx.OP_YARD_CTNMNG_WORK.Where(x => x.OP.ToString().ToUpper() == USERID.ToUpper() && (x.WORKSTATUS==""|| x.WORKSTATUS == null || x.WORKSTATUS=="未处理")).ToList(); if (detailList != null && detailList.Count > 0) { var bsnoList = detailList.Select(s => s.BSNO).ToList(); var headlist = wx.OP_YARD_CTNMNG.Where(x => bsnoList.Contains(x.GID)).ToList(); if (headlist != null && headlist.Count > 0) { resultList = headlist; } } return Json(new { ErrorCode = 0, data = resultList }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } */ private string 获得角色对应的工作内容名前缀(string USERID) { var wx = new WxAppDataContext(); var userinfo = wx.vw_user.First(x => x.USERID == USERID); var userrole = wx.Sys_Role_Core.First(x => x.Role_Id == userinfo.Role_Id); var worktype_startstr = ""; if (userrole.RoleName == "调度") { worktype_startstr = "调度"; } if (userrole.RoleName == "场站") { worktype_startstr = "场站"; } return worktype_startstr; } /// /// 虎鲸 小程序 /// 获取该用户需要执行的业务列表 /// /// /// [HttpGet] public ActionResult GetCTNMNGList(string USERID) { try { var resultList = new List(); var cdc = new CommonDataContext(); var wx = new WxAppDataContext(); //寻找这个人需要执行的业务内容 //寻找标准1 预计入场日期小于等于今天的预约业务 //寻找标准2 根据用户角色定义查询范围 //如果用户角色名为调度 则只显示 调度开头的worktype //将这些OP_YARD_CTNMNG_WORK的父节点OP_YARD_CTNMNG返回 //var _user = cdc.Users.FirstOrDefault(x => x.CODENAME == CODENAME); var worktype_startstr = 获得角色对应的工作内容名前缀(USERID); //今天 var endTime = DateTime.Today.AddDays(1).AddSeconds(-1);//.ToUniversalTime().ToString(); var 预约idlist = wx.OP_YARD_CTNMNG.Where(x => x.ENTERDATE <= endTime).Select(s=>s.GID).ToList(); //BasicDataRefDAL.SaveLog(headidlist, "", "wxapp", "虎鲸列表1"); var detailList = wx.OP_YARD_CTNMNG_WORK.Where(x => 预约idlist.Contains(x.BSNO) && x.WORKTYPE.StartsWith(worktype_startstr) && ( x.WORKSTATUS == "未处理")).ToList(); //BasicDataRefDAL.SaveLog(detailList, "", "wxapp", "虎鲸列表2"); var userloadport = GetLoadPortList(USERID); //BasicDataRefDAL.SaveLog(userloadport, "", "wxapp", "虎鲸列表3"); if (detailList != null && detailList.Count > 0) { List 需处理的预约idList = detailList.Select(s => s.BSNO).Distinct().ToList(); var tempList = wx.VW_OP_YARD_CTNMNG_HUJINGWXHeadList.Where(x => 需处理的预约idList.Contains(x.GID) && userloadport.Contains(x.LOADPORT) ).ToList(); List 需处理的台账IDList = tempList.Select(s => (Guid)s.BlockTrainOrderGid).ToList(); string get出库车号(Guid BlockTrainOrderGid) { return detailList.FirstOrDefault(x => x.BSNO== get待处理业务(BlockTrainOrderGid).GID).TRUCKNO; } VW_OP_YARD_CTNMNG_HUJINGWXHeadList get待处理业务(Guid BlockTrainOrderGid) { return tempList.FirstOrDefault(x => x.BlockTrainOrderGid == BlockTrainOrderGid); } //如果同时有堆场和保税预约 则只返回堆场预约 //且将BILLTYPE设定为 堆场预约/保税预约 foreach (var bsno in 需处理的台账IDList) { if (tempList.Exists(x => x.BlockTrainOrderGid == bsno && x.AppointType=="yard")) { var newrec = tempList.First(x => x.BlockTrainOrderGid == bsno && x.AppointType == "yard"); newrec.BILLTYPE = "堆场预约"; if (tempList.Exists(x => x.BlockTrainOrderGid == bsno && x.AppointType == "yard")) { newrec.BILLTYPE += "/保税预约"; } if (resultList.Exists(x => x.BlockTrainOrderGid == bsno)) continue; if (get待处理业务(bsno).BILLSTATUS_CUST == "待出场") { newrec.TRUCKNO = get出库车号(bsno); } resultList.Add(newrec); } else { var newrec = tempList.First(x => x.BlockTrainOrderGid == bsno && x.AppointType == "bond"); newrec.BILLTYPE = "保税预约"; if (get待处理业务(bsno).BILLSTATUS_CUST == "待出场") { newrec.TRUCKNO = get出库车号(bsno); } resultList.Add(newrec); } } //BasicDataRefDAL.SaveLog(resultList, "", "wxapp", "虎鲸列表4"); //foreach (var item in resultList) { // item.BILLTYPE = detailList.FirstOrDefault(x => x.BSNO == item.GID).WORKTYPE; //} //resultList = wx.VW_OP_YARD_CTNMNG_HUJINGWXHeadList.Where(x => 1 == 1).ToList(); } return Json(new { ErrorCode = 0, data = resultList }, JsonRequestBehavior.AllowGet); } catch (Exception e) { BasicDataRefDAL.SaveLog(e.Message, "", "wxapp", "虎鲸列表e"); return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } /// /// 虎鲸 小程序 /// 点击待执行业务进行的查询 /// /// /// /// [HttpGet] public ActionResult GetCTNMNGWORK_NeedDo(string GID, string USERID ) { try { var result = new OP_YARD_CTNMNG_WORK(); var cdc = new CommonDataContext(); var wx = new WxAppDataContext(); //寻找这个人在这项业务中需要执行的业务内容,并返回其中orderno最小的一项 var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID.ToString().ToUpper() == GID.ToUpper()); var order = wx.tb_BlockTrainOrder.FirstOrDefault(x => x.Gid == head.BlockTrainOrderGid); var worktype_startstr = 获得角色对应的工作内容名前缀(USERID); var detailList = wx.OP_YARD_CTNMNG_WORK.Where(x => x.BSNO==new Guid(GID) && x.WORKTYPE.StartsWith(worktype_startstr) && (x.WORKSTATUS == "未处理")).ToList(); if (detailList != null && detailList.Count > 0) { detailList = detailList.OrderBy(o => o.ORDERNO).ToList(); result = detailList[0]; } var ImgList = new List(); if (!string.IsNullOrWhiteSpace(result.IMGPATH)) { ImgList = result.IMGPATH.Split(',').ToList(); } var headlistrec = wx.VW_OP_YARD_CTNMNG_HUJINGWXHeadList.FirstOrDefault(x => x.GID == result.BSNO); var truckno = head.TRUCKNO; if (result.WORKTYPE == "场站出场") { truckno = result.TRUCKNO; } var _result = new { result.GID,BILLTYPE= head.AppointType_STR, CNTRNO= order.BoxCode , head.BILLSTATUS_CUST, CTNSTATUS= order.BoxStatus, result.WORKTYPE, result.WORKSTATUS, TRUCKNO= truckno, AREACODE= headlistrec.AREACODE, AREANAME = headlistrec.AREANAME, ImgList }; return Json(new { ErrorCode = 0, data = _result }, JsonRequestBehavior.AllowGet); } catch (Exception e) { BasicDataRefDAL.SaveLog(e.Message, "", "wxapp", "工作明细"); return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } [HttpGet] public ActionResult GetCTNMNGWORK(string GID ) { try { //var result = new OP_YARD_CTNMNG_WORK(); var cdc = new CommonDataContext(); var wx = new WxAppDataContext(); var result = wx.OP_YARD_CTNMNG_WORK.FirstOrDefault(x => x.GID==new Guid(GID)); var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == result.BSNO); var order = wx.tb_BlockTrainOrder.FirstOrDefault(x => x.Gid == head.BlockTrainOrderGid); var ImgList = new List(); if (!string.IsNullOrWhiteSpace(result.IMGPATH)) { ImgList = result.IMGPATH.Split(',').ToList(); } var _result = new { result.GID, BILLTYPE = head.AppointType_STR, CNTRNO = order.BoxCode, head.BILLSTATUS_CUST, CTNSTATUS = order.BoxStatus, result.WORKTYPE, result.WORKSTATUS, TRUCKNO = head.TRUCKNO, ImgList }; return Json(new { ErrorCode = 0, data = _result }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } [HttpGet] public ActionResult GetCanUseAreaCode(string USERID) { try { var result = new List(); var wx = new WxAppDataContext(); var AreaCodeHeadList = GetAreaCodeHeadList(USERID); var _r = wx.VW_OP_YARD_CTNMNG_STOREAREA_CANUSE.Where(x=>1==1).ToList(); if (AreaCodeHeadList != null && AreaCodeHeadList.Count > 0) { foreach (var item in _r) foreach(var headstr in AreaCodeHeadList) { if (item.AREACODE.StartsWith(headstr)) { result.Add(item); } } } result.Sort(delegate (VW_OP_YARD_CTNMNG_STOREAREA_CANUSE p1, VW_OP_YARD_CTNMNG_STOREAREA_CANUSE p2) { return p1.AREACODE.CompareTo(p2.AREACODE); }); return Json(new { ErrorCode = 0, data = result }, JsonRequestBehavior.AllowGet); } catch (Exception e) { return Json(new { ErrorCode = 500, Message = "发生错误:" + e.Message }, JsonRequestBehavior.AllowGet); } } [HttpPost] public ActionResult UploadFile_CTNMNG() { try { var GID = Request.Form["GID"].ToString().Trim(); var ISEND = Request.Form["ISEND"].ToString().Trim() == "true"; var TRUCKNO = Request.Form["TRUCKNO"].ToString().Trim(); var CNTRNO = Request.Form["CNTRNO"].ToString().Trim(); var USERID = Request.Form["USERID"].ToString().Trim(); var AREACODE = Request.Form["AREACODE"].ToString().Trim(); var DODATE = Request.Form["DODATE"].ToString().Trim(); var dayfilepath = DateTime.Today.ToString("yyyyMMdd"); var InfoFilesPath = "Upload/Tables/VW_INFO_FILES/" + dayfilepath;//保存到数据库info_files表的路径 BasicDataRefDAL.SaveLog(new { GID, ISEND, TRUCKNO, CNTRNO, USERID, AREACODE, DODATE }, USERID, "wxapp", "虎鲸app02"); string upDir = Path.Combine(ConfigurationManager.AppSettings["DSWMSPICPATH"], InfoFilesPath); if (!Directory.Exists(upDir)) { Directory.CreateDirectory(upDir); } //H:\DSWMS\Vue.Net\VOL.WebApi\wwwroot\Upload/Tables/VW_INFO_FILES/202012100909412467/1.jpg //向OP_YARD_CTNMNG_WORK的IMGPATH中追加图片地址。 var wx = new WxAppDataContext(); var workdetail = wx.OP_YARD_CTNMNG_WORK.FirstOrDefault(x => x.GID.ToString().ToUpper() == GID.ToUpper()); //判断此次上传图片数量加上现有图片是否超6张 如果是则返回错误 //改为app端判断 //var CurrentImgCount = workdetail.IMGPATH.Split(',').ToList().Count(); //var updcount = Request.Files.Count; //if (CurrentImgCount + updcount > 6) { // return Json(new { Success = false, Message = "图片数量超过6张,请确认后重新上传" }); //} if (Request.Files.Count > 0) { for (int c = 0; c < Request.Files.Count; c++) { var uploadFile = Request.Files[c]; if (uploadFile.ContentLength == 0) { continue; } var extension = Path.GetExtension(uploadFile.FileName); var timename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + new Random().Next(100, 999) + extension; var filepath = "\\" + timename;//随机生成文件名 var infofilepath = InfoFilesPath + "/" + timename; var savePath = upDir + filepath; uploadFile.SaveAs(savePath); if (!string.IsNullOrWhiteSpace(workdetail.IMGPATH)) { workdetail.IMGPATH += ","; } workdetail.IMGPATH += infofilepath; //InfoFileList.Add(new { id = DateTime.Now.Ticks, url = relativepath + filepath, size = uploadFile.ContentLength }); } wx.SaveChanges(); } if (ISEND) { workdetail.WORKSTATUS = "已处理"; //重新计算业务状态和集装箱状态 //var _r = DealStatus(workdetail,TRUCKNO,CNTRNO); //if (!_r.Success) { // return Json(new { Success = false, Message = "状态处理失败", Data = _r.Message }); //} //20220114 箱状态和预约状态变更 改为在后台系统中实现 //此处改为调用 SetStatus(workdetail, USERID,TRUCKNO,AREACODE,DODATE); } return Json(new { Success = true, Message = "上传成功", Data = JsonConvert.SerializeObject(workdetail.IMGPATH) }); } catch (Exception e) { return Json(new { Success = false, Message = e.Message }); } return Json(new { Success = false, Message = "没有文件" }); } [HttpPost] public ActionResult CTNMNG_WorkDo() { try { var GID = Request.Form["GID"].ToString().Trim(); var ISEND = Request.Form["ISEND"].ToString().Trim() == "true"; var TRUCKNO = Request.Form["TRUCKNO"].ToString().Trim(); var CNTRNO = Request.Form["CNTRNO"].ToString().Trim(); var USERID = Request.Form["USERID"].ToString().Trim(); var AREACODE = Request.Form["AREACODE"].ToString().Trim(); var DODATE = Request.Form["DODATE"].ToString().Trim(); BasicDataRefDAL.SaveLog(new{ GID , ISEND , TRUCKNO, CNTRNO, USERID, AREACODE, DODATE }, USERID, "wxapp", "虎鲸app01"); var wx = new WxAppDataContext(); var workdetail = wx.OP_YARD_CTNMNG_WORK.FirstOrDefault(x => x.GID.ToString().ToUpper() == GID.ToUpper()); if (ISEND) { workdetail.WORKSTATUS = "已处理"; SetStatus(workdetail, USERID,TRUCKNO,AREACODE,DODATE); } //return GetCTNMNGWORK(GID); return Json(new { Success = true, Message = "执行成功", Data = ""}); } catch (Exception e) { return Json(new { Success = false, Message = e.Message }); } return Json(new { Success = false, Message = "没有文件" }); } public string SetStatus(OP_YARD_CTNMNG_WORK workdetail,string USERID,string TRUCKNO,string AREACODE,string DODATE) { var result = ""; var wx = new WxAppDataContext(); var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); var dswmsurl = ConfigurationManager.AppSettings["DSWMSURL"] + "OP_YARD_CTNMNG/PublicFunc"; var dic = new Dictionary(); dic.Add("TYPENAME", "CTNMNGDOWORK"); dic.Add("GID", workdetail.BSNO.ToString()); dic.Add("WORKTYPE", workdetail.WORKTYPE); dic.Add("USERID", USERID); dic.Add("AREACODE", AREACODE); dic.Add("TRUCKNO", TRUCKNO); dic.Add("DODATE", DODATE); //BasicDataRefDAL.SaveLog(dic, USERID, "wxapp", "虎鲸app1"); var rtn = WebRequestHelper.DoPost_DSWMS(dswmsurl, dic, 50000); BasicDataRefDAL.SaveLog("SetStatus:"+ rtn, USERID, "wxapp", "虎鲸app2"); return result; } public class UserLoadPortListmb { public bool Status { get; set; } public List Data { get; set; } } public List GetLoadPortList(string USERID) { var dswmsurl = ConfigurationManager.AppSettings["DSWMSURL"] + "OP_YARD_CTNMNG/PublicFunc"; var dic = new Dictionary(); dic.Add("TYPENAME", "GetUserLoadPort"); dic.Add("GID", ""); dic.Add("WORKTYPE", ""); dic.Add("USERID", USERID); dic.Add("AREACODE", ""); dic.Add("TRUCKNO", ""); dic.Add("DODATE", ""); var rtn = WebRequestHelper.DoPost_DSWMS(dswmsurl, dic, 50000); BasicDataRefDAL.SaveLog("GetLoadPortList:" + rtn, USERID, "wxapp", "虎鲸app"); UserLoadPortListmb pt = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); return pt.Data; } public List GetAreaCodeHeadList(string USERID) { var dswmsurl = ConfigurationManager.AppSettings["DSWMSURL"] + "OP_YARD_CTNMNG/PublicFunc"; var dic = new Dictionary(); dic.Add("TYPENAME", "GetAreaCodeHeadList"); dic.Add("GID", ""); dic.Add("WORKTYPE", ""); dic.Add("USERID", USERID); dic.Add("AREACODE", ""); dic.Add("TRUCKNO", ""); dic.Add("DODATE", ""); var rtn = WebRequestHelper.DoPost_DSWMS(dswmsurl, dic, 50000); BasicDataRefDAL.SaveLog("GetAreaCodeHeadList:" + rtn, USERID, "wxapp", "虎鲸app"); UserLoadPortListmb pt = Newtonsoft.Json.JsonConvert.DeserializeObject(rtn); return pt.Data; } //[HttpGet] //public ActionResult GetAreacode_canuse() { //} /// /// 删除图片 /// 如果关联的入库执行没有处于1001状态,则不允许删除 /// /// [HttpGet] public ActionResult DelFile_CTNMNG(string GID,string PICSRC) { try { var wx = new WxAppDataContext(); //1首先找到这条业务明细 和它的父节点业务 var workdetail = wx.OP_YARD_CTNMNG_WORK.FirstOrDefault(x => x.GID == new Guid(GID)); var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); //2判断关联业务的状态 看能否删除 if (head.BILLSTATUS_CUST == "待发运") { return ErrorResult("业务完成,不可删除图片"); } //3执行删除 即将workdetail当中的imgpath里面,指定名称的图片路径去除。 var imgList = workdetail.IMGPATH.Split(',').ToList(); foreach (var img in imgList) { if (PICSRC.IndexOf(img) > 0) { workdetail.IMGPATH=workdetail.IMGPATH.Replace("," + img,""); workdetail.IMGPATH=workdetail.IMGPATH.Replace(img+ ",", ""); workdetail.IMGPATH=workdetail.IMGPATH.Replace( img, ""); } } wx.SaveChanges(); } catch (Exception e) { return ErrorResult(e.Message); } return ErrorResult("没有可以删除的文件"); } /* public class 箱状态factory { public static 箱状态 Get箱业务(OP_YARD_CTNMNG_WORK workdetail) { var wx = new WxAppDataContext(); var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); if (head.BILLTYPE == "保税转入") { return new 箱状态_保税转入(head); } if (head.BILLTYPE == "保税落箱" || head.BILLTYPE == "分类监管") { return new 箱状态_保税落箱分类监管(head); } if (head.BILLTYPE == "拼箱集运") { return new 箱状态_拼箱集运(head); } return null; } } public abstract class 箱状态 { public OP_YARD_CTNMNG head { get; set; } public List worklist { get; set; } public 箱状态() { } public abstract string Get箱状态(); } public class 箱状态_保税转入 : 箱状态 { public 箱状态_保税转入(OP_YARD_CTNMNG _head) { var wx = new WxAppDataContext(); head = _head; //worklist = OP_YARD_CTNMNG_WORKRepository.Instance.FindAsIQueryable(x => x.BSNO == head.GID).ToList(); worklist = wx.OP_YARD_CTNMNG_WORK.Where(x => x.BSNO == head.GID).ToList(); } public override string Get箱状态() { worklist = worklist.OrderBy(o => o.ORDERNO).ToList(); foreach (var item in worklist) { if (item.WORKSTATUS == "已处理") { if (item.WORKTYPE == "调度入区") head.CTNSTATUS = "待入区"; if (item.WORKTYPE == "调度出区") head.CTNSTATUS = "正在申报出区"; if (item.WORKTYPE == "卡口作业") head.CTNSTATUS = "正在前往铁路货场"; if (item.WORKTYPE == "铁路验查作业") head.CTNSTATUS = "等待铁路查验"; if (item.WORKTYPE == "铁路发运作业") head.CTNSTATUS = "待发运"; } } return head.CTNSTATUS; //throw new global::System.NotImplementedException(); } } public class 箱状态_保税落箱分类监管 : 箱状态 { public 箱状态_保税落箱分类监管(OP_YARD_CTNMNG _head) { head = _head; var wx = new WxAppDataContext(); worklist = wx.OP_YARD_CTNMNG_WORK.Where(x => x.BSNO == head.GID).ToList(); } public override string Get箱状态() { worklist = worklist.OrderBy(o => o.ORDERNO).ToList(); foreach (var item in worklist) { if (item.WORKSTATUS == "已处理") { if (item.WORKTYPE == "调度入区") head.CTNSTATUS = "待入区"; if (item.WORKTYPE == "仓库作业") head.CTNSTATUS = "已入区落箱"; if (item.WORKTYPE == "调度出区") head.CTNSTATUS = "正在申报出区"; if (item.WORKTYPE == "卡口作业") head.CTNSTATUS = "正在前往铁路货场"; if (item.WORKTYPE == "铁路验查作业") head.CTNSTATUS = "等待铁路查验"; if (item.WORKTYPE == "铁路发运作业") head.CTNSTATUS = "待发运"; } } return head.CTNSTATUS; //throw new global::System.NotImplementedException(); } } public class 箱状态_拼箱集运 : 箱状态 { public 箱状态_拼箱集运(OP_YARD_CTNMNG _head) { head = _head; var wx = new WxAppDataContext(); worklist = wx.OP_YARD_CTNMNG_WORK.Where(x => x.BSNO == head.GID).ToList(); } public override string Get箱状态() { worklist = worklist.OrderBy(o => o.ORDERNO).ToList(); foreach (var item in worklist) { if (item.WORKSTATUS == "已处理") { if (item.WORKTYPE == "仓库作业") head.CTNSTATUS = "正在装箱"; if (item.WORKTYPE == "调度入区") head.CTNSTATUS = "待入区"; if (item.WORKTYPE == "调度出区") head.CTNSTATUS = "正在申报出区"; if (item.WORKTYPE == "卡口作业") head.CTNSTATUS = "正在前往铁路货场"; if (item.WORKTYPE == "铁路验查作业") head.CTNSTATUS = "等待铁路查验"; if (item.WORKTYPE == "铁路发运作业") head.CTNSTATUS = "待发运"; } } return head.CTNSTATUS; //throw new global::System.NotImplementedException(); } } */ /// /// 用于微信小程序修改车号和箱号 /// /// /// /// /// /// /* public DBResult DealStatus(OP_YARD_CTNMNG_WORK workdetail,string TRUCKNO,string CNTRNO) { var wx = new WxAppDataContext(); //只有 调度入区 作业允许修改箱号 if (workdetail.WORKTYPE == "调度入区") { var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); head.CNTRNO = CNTRNO; wx.SaveChanges(); } //只有 调度入区/调度出区/卡口作业 允许修改工作明细的车号 if (workdetail.WORKTYPE == "调度入区"|| workdetail.WORKTYPE == "调度出区" || workdetail.WORKTYPE == "卡口作业") { //workdetail.TRUCKNO = TRUCKNO; var changerecord = wx.OP_YARD_CTNMNG_WORK.FirstOrDefault(x => x.GID == workdetail.GID); changerecord.TRUCKNO = TRUCKNO; if (workdetail.WORKTYPE == "调度入区") { var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); head.TRUCKNO_IN = TRUCKNO; } if (workdetail.WORKTYPE == "调度出区") { var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); head.TRUCKNO_OUT = TRUCKNO; } wx.SaveChanges(); } return DealStatus( workdetail); } public DBResult DealStatus(OP_YARD_CTNMNG_WORK workdetail) { var result = new DBResult(); try { var wx = new WxAppDataContext(); //分为两部分。一部分是更改顺序号较低业务的状态,由空改为未执行 //二部分是根据目前该业务的各明细的执行状态(状态为已处理的那条明细),修改该业务的箱状态 //《1》业务逻辑如下:查找所有顺序小于该明细的业务明细,如果WORKSTATUS="",将之更新为 "未处理" result = DelOldDetail(workdetail); if (!result.Success) return result; //《2》业务逻辑如下:查找状态为“已处理”的最大顺序号业务,配合其“引入方式”,获取其对应的箱状态 并写入主表 //var f = new 箱状态factory(); var 箱业务 = 箱状态factory.Get箱业务(workdetail); var head = wx.OP_YARD_CTNMNG.FirstOrDefault(x => x.GID == workdetail.BSNO); head.CTNSTATUS = 箱业务.Get箱状态(); wx.SaveChanges(); result.OK(); return result; } catch (Exception e) { result.SetErrorInfo(e.Message); return result; } } private static DBResult DelOldDetail(OP_YARD_CTNMNG_WORK workdetail) { var result = new DBResult(); var wx = new WxAppDataContext(); var oldDetailList = wx.OP_YARD_CTNMNG_WORK.Where(x => x.BSNO == workdetail.BSNO && x.ORDERNO < workdetail.ORDERNO).ToList(); if (oldDetailList == null || oldDetailList.Count == 0) { result.OK(); return result; } //var updList = new List(); var needupd = false; foreach (var item in oldDetailList) { if (item.WORKSTATUS == "") { item.WORKSTATUS = "未处理"; //updList.Add(item); needupd = true; } } if (needupd) { //var i = OP_YARD_CTNMNG_WORKRepository.Instance.UpdateRange(updList, true); wx.SaveChanges(); } result.OK(); return result; } */ } }