using JCSoft.WX.Framework.Api; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Common.Wechat; using Common; using System.Data; using ZcPeng.PublicLibrary; using CoreEntity.Entity; using Common.Model; using Newtonsoft.Json.Converters; using Newtonsoft.Json; using System.Data.SqlClient; using ZcPeng.weixin.PublicAccount; using CoreEntity.DAL; using PublicLibrary.Model; using Microsoft.Extensions.Caching.Memory; using CoreEntity.BAL; using static CoreEntity.BAL.PushBAL; using SupplierWeb.Codes.mvc; using SupplierWeb.Codes.Push; using CoreEntity.TimedTask; using System.Collections.Concurrent; using Microsoft.AspNetCore.Hosting; using static SupplierWeb.Controllers.NewGoodsController; using System.IO; using Npoi.Mapper; using LigerRM.Common; namespace SupplierWeb.Controllers { [Route("web/pushall")] public class PushController : BaseController { public PushController(IMemoryCache cache, IApiClient client) : base(cache, client) { } private ConcurrentDictionary roleMap = new ConcurrentDictionary(); [AuthPermission] [HttpPost, Route("permissionRole")] public JsonResult PermissionRole(QueryFilter[] filters, String permissions, [FromBody]dynamic data) { string result; String roleids = ""; if (data != null) { filters = data.filters.ToObject(); permissions = data.temp; } #region 获取权限列表 DataTable dt = new DataTable(); IList permss = new List(0); List parameters = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Permission(), "A."); #endregion if (dt != null && dt.Rows.Count > 0) { // 把DataTable转换为IList permss = ModelConvertHelper.ConvertToModel(dt); #region 获取权限的角色列表 //角色列表 IList roles = RoleDAL.GetRoles(); // 把DataTable转换为IList if (roleMap.Count < roles.Count) { foreach (Role role in roles) { roleMap.TryAdd(role.Id, role); } } //for (var i = 0;i < ) //{ //} String permissionIds = permissions.Substring(0, permissions.Length - 1); string commonText = "select RO.roleId as roleId from " + Config.TablePrefix + "Permission A," + Config.TablePrefix + "RoleRelatePermission RP " + " WHERE 1=1 AND A.isdelete = '0' AND A.AuthType in('A','O') " + "and A.id = RP.PermissionId and A.id in (" + permissionIds + ")"; bool success = DataAccess.GetValues(commonText, ref dt, parameters.ToArray(), out result); // 把DataTable转换为IList if (dt != null && dt.Rows.Count > 0) { IList permRelates = ModelConvertHelper.ConvertToModel(dt); List superior_list = new List(0); foreach (RoleRelatePermission permsr in permRelates) { superior_list.Add(permsr.RoleId); } roleids = string.Join(",", superior_list.ToArray()); } //} #endregion } IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; var jsonData = JsonConvert.SerializeObject(permss, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, RoleId = roleids }); } /// ////手动保存并推送: ///选出已经建立账户的供应商业务员推送 /// /// 推送id /// /// [AuthPermission] [HttpPost, Route("saveandpush")] public ActionResult SaveAndPush( //string Id, DateTime start, [FromBody]dynamic data) { string userids; string LoginAccountId = userids = getStaff("userid"); string RoleId = getStaff("roleid"); //判断参数是否合法 if (string.IsNullOrEmpty(userids)) { return Json(new { success = 0, msg="没有登陆" }); } string[] goodsIds = null; PushContactWithGoods[] contacws = null; if (data != null) { //Newtonsoft.Json.Linq.JArray //Id = data.Id; goodsIds = data.goodsIds.ToObject(); contacws = data.contactws.ToObject(); } string filterlimit = ""; string filtercont = ""; //string filtercontact = ""; //if (Id != null&& Id != "") //{ // filterlimit = // "and GoodsId in (select GoodsId from " // + Config.TablePrefix+"PushFeedback where " + // "PushRecordId = "+Id+")"; // filtercontact = " and exists (select 1 from " // + Config.TablePrefix + "PushFeedback where 1=1 " + // " and PushRecordId = " + Id + "" + // " and PushAccountId = UserId " + // ") "; //} if (goodsIds!=null && goodsIds.Length > 0) { string goodsIdStr = string.Join("','", goodsIds); filterlimit = " and GoodsId in ('" + goodsIdStr + "') "; string contactwgs = string.Join("','", contacws.Where(contact => (contact.ContactId != "" && contact.ContactId !=null))); filtercont = " and ContactId in ('" + contactwgs + "') "; } if (start != null && !start.ToString().StartsWith("0001")) { TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), RoleId, LoginAccountId, filterlimit,filtercont, _client).GetAwaiter().GetResult(); } /* //获取推送上下限 IList pushLimits = PushRecordDAL.GetPushLimit(filterlimit); if(pushLimits.Count == 0) return Json(new { success = 0, result = "没有选择库存低于下限品种", }); // 获取待推联系人 绑定账户 和微信 string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId); string filterstr = filtercont+" and UserId IS NOT NULL and UserId !=''" + //" and FocusMicNo IS NOT NULL and FocusMicNo !='' " + FilterRuleByPur.getRolePermFilter(RoleId, " and SaleManId = '" + StaffDocId + "' ") //只查询当前采购员的联系人 //+ filtercontact ; Dictionary gapnum; List GetPushContacts = ContactBAL.GetPushContactWithGoods( filterstr,"", pushLimits, out gapnum); //判断参数是否合法 if (GetPushContacts.Count == 0) { return Json(new { success = 0, msg = "没有建立账户,或者业务员没有绑定" }); } var result = PushBAL.pushAll(GetPushContacts, gapnum, LoginAccountId, _client); var codeids = result[result.Count - 1]; Object Ids; codeids.TryGetValue("Ids",out Ids); List ids = (List)Ids; foreach (String recordId in ids) { CancelPushRecordTimedJob.CancelPushRecord(recordId,DateTime.Now, CancelPushRecordTimedJob.HoursToCancel); } */ bool success = PushBAL.Push(LoginAccountId, RoleId,filterlimit,filtercont, out var result,_client); return Json(new { success = success, result = result, }); } //自动推送 [AuthPermission] [HttpPost, Route("push")] public ActionResult Push( DateTime start, [FromBody]dynamic data) { string userids; string LoginAccountId = userids = getStaff("userid"); string RoleId = getStaff("roleid"); //判断参数是否合法 if (string.IsNullOrEmpty(userids)) { return Json(new { success = 0, msg = "没有登陆" }); } string[] goodsIds = null; PushContactWithGoods[] contacws = null; if (data != null) { //Newtonsoft.Json.Linq.JArray start = data.start; goodsIds = data.goodsIds.ToObject(); contacws = data.contactws.ToObject(); } string filterlimit = ""; string filtercont = ""; if (goodsIds != null && goodsIds.Length > 0) { string goodsIdStr = string.Join("','", goodsIds); filterlimit = " and GoodsId in ('" + goodsIdStr + "') "; string contactwgs = string.Join("','", contacws.Where(contact => (contact.ContactId != "" && contact.ContactId != null))); filtercont = " and ContactId in ('" + contactwgs + "') "; } TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), RoleId, LoginAccountId, filterlimit,filtercont,_client).GetAwaiter().GetResult(); return Json(new { success = 1 }); } ////供应商业务员修改过的记录:手动保存并添加待推业务员: //[AuthPermission] //[HttpPost, Route("saveandrepush/{editpush}")] //public ActionResult SaveAndRePush( // string Id, string LoginAccountId, // DateTime start, // int editpush, // List pfbs, // [FromBody]dynamic data) //{ // string RecordId = string.Empty; // if (data != null) // { // //Newtonsoft.Json.Linq.JArray // Id = data.Id; // if (Id != null) // RecordId = Id; // LoginAccountId = data.LoginAccountId; // start = data.PushTime!=null? data.PushTime:DateTime.Now; // pfbs = data.pfbs.ToObject(); // } // //string userids; // //string LoginAccountId = userids = getStaffUserid(staffId); // //判断参数是否合法 // if (string.IsNullOrEmpty(LoginAccountId)) // { // return Json(new // { // success = 0, // msg = "没有登陆" // }); // } // //if (start != null && !start.ToString().StartsWith("0001")) // //{ // // TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), _client).GetAwaiter().GetResult(); // //} // string filterlimit = ""; // string filtercontact = ""; // if (Id != null && Id != "") // { // filterlimit = // " and GoodsId in (select GoodsId from LJHYBZK.dbo." // + Config.TablePrefix + "PushFeedback where 1=1 " + // " and PushRecordId = '" + Id + "' " + // " and State IS NULL or State in (0,6,5)" + // ")"; // filtercontact = " and exists (select 1 from " // + Config.TablePrefix + "PushFeedback A where 1=1 " + // " and A.PushRecordId = '" + Id + "' " + // " and State IS NULL or State in (0,6,5) " + // " and PushAccountId = UserId " + // " and A.GoodsId = GoodsId " + // ")"; // } // //获取推送上下限 // IList pushLimits = PushRecordDAL.GetPushLimit(filterlimit); // string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId); // // 获取待推联系人 绑定账户 保存推送记录不需要绑定微信 // string filterstr = // " and UserId IS NOT NULL and UserId !=''" + // //" and FocusMicNo IS NOT NULL and FocusMicNo !='' "+ // //" and SaleManId = '"+StaffDocId+"' " +//只查询当前采购员的联系人 // filtercontact; // Dictionary gapnum; // List GetPushContacts = ContactBAL.GetPushContactWithGoods(filterstr, ",t1.ContactId,t1.SuppliersId ", pushLimits, out gapnum); // //判断参数是否合法 // if (GetPushContacts.Count == 0) // { // return Json(new // { // success = 0, // msg = "业务员没有绑定,或者没有建立账户" // }); // } // DateTime EndTime = DateTime.Now.AddHours((double)24); // String loginAccountId = string.Empty; // string filter = ""; // if (editpush == 0) // filter = " and State in (5,6) "; // else if(editpush == 1) // filter = " and State IS NULL or State = 0 " + // " "; // List list = PushFeedBackDAL.GetFeedbacks(Id, filter); // PushRecord prec = PushRecordDAL.GetRecord(Id); // List result = new List(); // int successAll = 1; // foreach(PushFeedback feedback in list) { // int OldPushAccountId = feedback.PushAccountId; // int newPushAccountId = OldPushAccountId; // PushFeedback newpfb = null; // foreach (PushFeedback pfb in pfbs) // { // //根据userid 初始化PushAccountId SuppliersId // string[] ContactIds = pfb.ContactId.Split("_"); // string PushAccountId = ""; // if (ContactIds.Length > 2) // { // pfb.ContactId = ContactIds[0]; // pfb.SuppliersId = ContactIds[1]; // PushAccountId = ContactIds[3]; // } // if(PushAccountId!=null&& PushAccountId != "") // pfb.PushAccountId = Convert.ToInt32(PushAccountId); // if (PushAccountId == ""|| PushAccountId==null) // { // return Json(new // { // success = 0, // msg = "业务员没有绑定,或者没有建立账户" // }); // } // ////ContactDoc cdoc = AccountDAL.getContactor(pfb.ContactId); // //List users = ContactBAL.GetPushContactWithGoods( // // " and ContactId in ('" + ContactId + "') " + // // " and GoodsId in ('" + pfb.GoodsId + "')", ",t1.ContactId,t1.SuppliersId", // // new List(), // // out gapnum); // //PushContactWithGoods cdoc = null; // //if (users.Count > 0) { // // cdoc = users[0]; // //} // //else // //{//contactid不合法 // // return Json(new // // { // // success = 0, // // msg = "contactid不合法" // // }); // //} // //if (cdoc.UserId!=null&& cdoc.UserId != "") { // // pfb.PushAccountId = Convert.ToInt32(cdoc.UserId); // // pfb.SuppliersId = cdoc.SuppliersId; // //} // if (pfb.Id.Equals(feedback.Id)) { // newpfb = pfb; // if ( pfb.PushAccountId != Convert.ToInt32(OldPushAccountId) // || pfb.SuppliersId != feedback.SuppliersId) // { // Message msg = TimeTask.sendSupplyMassMesage(_client, // Convert.ToInt32(feedback.PushAccountId), // pfb.PushRecordId.ToString(), // feedback.GoodsName, // feedback.StoreGapNum.ToString(), // feedback.PurPrice.ToString(), // EndTime); // newPushAccountId = pfb.PushAccountId; // result.Add(msg); // } // } // } // //添加或修改推送记录 // IDictionary successs = // PushRecordDAL.AddOrUpdatePushFeedBack( // prec.PushCode, // Id // , feedback.Id.ToString(), // newPushAccountId, // newpfb.ContactId, // feedback.GoodsId, feedback.GoodsCode // , feedback.GoodsName, feedback.StoreGapNum // , feedback.GoodsSpec, feedback.Manufacturer // , feedback.BusinessId, feedback.BusinessCode, feedback.BusinessName // , feedback.SuppliersId, feedback.BrandName, feedback.BrandId // , feedback.EntId, feedback.Remark, LoginAccountId // , feedback.PurPrice // , feedback.ActPrice // , feedback.PurchaseTotalNum); // result.Add(successs); // Object successDT; // Object resultDT; // successs.TryGetValue("successRecord", out successDT); // successs.TryGetValue("resultRecord", out resultDT); // if (((string)resultDT).StartsWith("在执行数据操作时发生错误")) // { // successAll = 0; // } // } // if(successAll > 0) // { // #region 更新记录 // string commandTextRecord = "UPDATE " + Config.TablePrefix + "PushRecord " + // " SET LastModifiedPerson = @LastModifiedPerson, " + // " State = 5 " + // " WHERE Id= @RecordId "; // string resultRecord; // //准备参数 // List> parametersRecord = new List>(); // parametersRecord.Add(new List() { "RecordId", Id }); // parametersRecord.Add(new List() { "LastModifiedPerson", Convert.ToInt32(LoginAccountId) }); // List parametersRecord1 = DataAccess.ToParameters(parametersRecord); // int successRecord = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord); // #endregion // result.Add(successRecord); // result.Add(resultRecord); // } // return Json(new // { // success = successAll, // successAll = successAll, // result = result, // }); //} ////修改过供应商的记录重推 //[AuthPermission] //[HttpPost, Route("repush")] //public ActionResult RePush(string LoginAccountId, // DateTime start) //{ // string filter = " and State in (5,6) "; // List list = PushFeedBackDAL.GetFeedbacks(new List(), filter); // List result = new List(); // #region 更新记录 // List listcmd = new List(); // string resultFeed; // int successAll = 1; // DateTime EndTime = DateTime.Now.AddHours((double)24); // foreach (PushFeedbackExt feedback in list) // { // Message msg = TimeTask.sendSupplyMassMesage(_client, // Convert.ToInt32(feedback.PushAccountId), // feedback.PushRecordId.ToString(), // feedback.GoodsName, // feedback.StoreGapNum.ToString(), // feedback.PurPrice.ToString(), // EndTime); // result.Add(msg); // string commandTextFeed = "UPDATE " + Config.TablePrefix + "PushFeedback " + // " SET IsPush = @IsPush, " + // " WHERE Id= @Id AND (state in (5,6)) " + // " and IsPush = 0"; // //准备参数 // List> parametersFeed = new List>(); // parametersFeed.Add(new List() { "Id", feedback.Id }); // parametersFeed.Add(new List() { "IsPush", 1 }); // List parametersFeed1 = DataAccess.ToParameters(parametersFeed); // listcmd.Add(new DataAccessCommand(commandTextFeed, parametersFeed1, CommandType.Text, true)); // } // bool success = DataAccess.ExecuteBatchCommands(listcmd, out resultFeed); // #endregion // return Json(new // { // success = success, // successAll = successAll, // result = resultFeed, // }); //} ///保存到采购计划 [HttpPost, Route("savetoplan")] [AuthPermission] public ActionResult SaveToPlan( string Id , string LoginAccountId, //Int32 ReceiptMd, Int32 CentPayMd, PushFeedbackExt[] pfbs, string EntId, string OrgId,String DeptId, // DateTime RequestDate, [FromBody]dynamic data) { if (data != null) { //Newtonsoft.Json.Linq.JArray Id = data.Id; LoginAccountId = data.LoginAccountId; //ReceiptMd = data.ReceiptMd; //CentPayMd = data.CentPayMd; OrgId = data.OrgId; DeptId = data.DeptId; //RequestDate = data.RequestDate; pfbs = data.pfbs ==null? new PushFeedbackExt[] { } : data.pfbs.ToObject(); } //PushRecord rec = PushRecordDAL.GetRecord(Id); //int IsCompleteAll = 1; //if (IsCompleteAll == 1) // return Json(new // { // success = 0, // msg = "已经全部生成采购计划!" // }); //List listAll = PushFeedBackDAL.GetFeedbacks(Id); List list = PushFeedBackDAL.GetFeedbacks(Id," and state in (1,2) "); // if(list == null) { return Json(new { success = 0, msg = "不能重复提交,已经全部生成采购计划!" }); } Dictionary> groups = new Dictionary>(); Dictionary groupGoodsNames = new Dictionary(); //Dictionary haveSupp = new Dictionary(); foreach (PushFeedbackExt fb in list) { //初始化付款方式 发货方式 要求日期 foreach (PushFeedbackExt fb0 in pfbs) { if (fb0.Id.Equals(fb.Id)) { //采购员可以编辑付款方式 fb.CentPayMd = fb0.CentPayMd; fb.ReceiptMd = fb0.ReceiptMd; fb.RequestDate = fb0.RequestDate; fb.Remark = fb0.Remark; //采购员可以编辑供货数量 fb.StoreGapNum = fb0.StoreGapNum; //预付款 fb.PrepayAmt = fb0.PrepayAmt; fb.IsPrepay = fb0.IsPrepayI == 1?"Y":"N"; //对方业务员,isyw='Y' and IsSaleDelegate='N' fb.OppContId = fb0.OppContId; } } if (fb.StoreGapNum > 0) { ContactDoc cd = ContactDAL.getContactor(fb.ContactId); string SuppliersId = fb.SuppliersId; if (cd != null) SuppliersId = cd.BusinessId; fb.SuppliersId = SuppliersId; fb.BusinessId = SuppliersId; var accountSuppliers = fb.PushAccountId +"_" + SuppliersId; if (groups.ContainsKey(accountSuppliers)) { List to; groups.TryGetValue(accountSuppliers, out to); to.Add(fb); groups.Remove(accountSuppliers); groups.Add(accountSuppliers, to); } else { List to = new List(); to.Add(fb); groups.Add(accountSuppliers, to); } } //生成计划 string contactid = fb.ContactId; if (fb.StoreGapNum <= 0)//对方没货 找下一个有货的供应商推送 生成计划前推送状态Y 生成计划后生成计划前推送状态N { //删除明细 //PushFeedBackDAL.DeleteFeedback(fb.Id.ToString()); ContactDAL.UpdatePushContactState(fb.GoodsId, contactid, fb.SuppliersId.Trim(), "Y", null); } else {//有货的记录需要推送状态为N 生成计划算在途 ContactDAL.UpdatePushContactState(fb.GoodsId, contactid, fb.SuppliersId.Trim(), "N", null); } PushInfo.saveGoodsNames(fb, ref groupGoodsNames); } List result = new List(); int successAll = 0; int tempSuccess = 1; foreach (string groupkey in groups.Keys) { DateTime EndTime = DateTime.Now.AddHours((double)24); //string LoginStaffId = StaffDocDAL.GetStaffId(LoginAccountId);//改成谁绑定的品种就是谁的订单 List to; groups.TryGetValue(groupkey, out to); PushFeedbackExt fb0 = to.ToArray()[0]; string StaffId = fb0.SaleManId; //添加采购计划 IDictionary successs = PushRecordDAL.AddPlan(Id, fb0.Id.ToString(), fb0.PushAccountId, fb0.EntId, fb0.ReceiptMd, fb0.CentPayMd , OrgId, DeptId//depid , "采购计划", fb0.Remark //Summaries , fb0.GoodsId, fb0.SuppliersId , fb0.BusinessId, fb0.BusinessCode , StaffId , fb0.RequestDate , fb0.PrepayAmt , fb0.IsPrepay , fb0.OppContId , fb0.ContactId); Dictionary successsR = new Dictionary(); successsR.Add("successsPlan", successs); Object successPlan; successs.TryGetValue("successRecord", out successPlan); //billno Object PlanBillNo0; successs.TryGetValue("PlanBillNo", out PlanBillNo0); int PlanBillNo = (int)PlanBillNo0; if ((int)successPlan > 0) { List resultDt = new List(); int index = 1; foreach (PushFeedbackExt feedback in to) { Decimal LastPrice = feedback.PurPrice; string Summaries = feedback.Feedback; //添加采购计划明细 int SafeDays = 0; IDictionary successs1 = PushRecordDAL.AddPlanDT(feedback.Id.ToString(), PlanBillNo, index, feedback.GoodsId, feedback.GoodsSpec, Convert.ToInt32(feedback.StoreGapNum), LastPrice, feedback.Remark, feedback.EntId, feedback.BusinessId, feedback.BusinessCode, feedback.SuppliersId, Convert.ToInt32(feedback.PurchaseTotalNum), SafeDays , StaffId , feedback.RequestDate); resultDt.Add(successs1); Object successPlanDT1; successs1.TryGetValue("successRecord", out successPlanDT1); if((int)successPlanDT1 > 0) { //更新推送状态 生成计划 string resultState; var successState = PurPlanDAL.UpdatePlanState(feedback.Id.ToString(), Id, LoginAccountId,out resultState, " Remark = '" + feedback.Remark + "',StoreGapNum = '" + feedback.StoreGapNum + "'," + "OppContId = '" + feedback.OppContId + "',"); if (resultState.StartsWith("在执行数据操作时发生错误")) tempSuccess = 0; } //记录失败 else { tempSuccess = 0; } index += 1; } successsR.Add("successsPlanDT", resultDt); } else { //记录失败 tempSuccess = 0; } result.Add(successsR); } if ((int)tempSuccess > 0)//&& listAll.Count == list.Count 全部生成计划 { //更新推送状态 生成计划 string resultState; var successState = PurPlanDAL.UpdateRecordPlanState(Id, LoginAccountId,out resultState); result.Add(successState); if (resultState.StartsWith("在执行数据操作时发生错误")) successAll = 1; foreach(string groupkey in groupGoodsNames.Keys) { //推送计划 PushInfo pushInfos = null; groupGoodsNames.TryGetValue(groupkey, out pushInfos); DateTime EndTime = DateTime.Now.AddHours((double)Config.HoursToCancel); Message msg = PlanBAL.PushPlan(_client, Convert.ToInt32(groupkey), Id, pushInfos.GoodsName, pushInfos.GoodsNums, pushInfos.TotalAmount, EndTime); Dictionary msgd = new Dictionary(1); msgd.Add("msg", msg); result.Add(msgd); } } if (tempSuccess > 0) { return Json(new { success = 1, result = result, successAll = successAll }); } else { return Json(new { success = 0, result = result, successAll = successAll }); } } ////待推送联系人--所有推送的业务员,查询业务员的推送记录 [AuthPermission] [HttpPost, Route("pendingcontacts")] public JsonResult PendingContacts(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize, string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data) { string LoginAccountId = getStaff("userid"); string RoleId = getStaff("roleid"); //判断参数是否合法 if (string.IsNullOrEmpty(LoginAccountId)) { return Json(new { items = new string[] { }, sum = new { }, totalCount = 0, timeout = 1 }); } if (data != null) { //Newtonsoft.Json.Linq.JArray filters = data.filters.ToObject(); pageIndex = data.pageIndex; pageSize = data.pageSize; sortField = data.sortField; sortDirection = data.sortDirection; sumFields = data.sumFields.ToObject(); } #region 获取待推联系人 DataTable dt = new DataTable(); string result = string.Empty; string direct = " desc "; if (sortDirection != 1) direct = " asc"; int start = (pageIndex - 1) * pageSize; int end = (start + 1 + pageSize); //string filterstr = QueryFilter.getFilterString(filters); List parameters1 = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new PushContactWithGoods()); string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId); //filterstr += ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and SaleManId = '" + StaffDocId + "' ")); filterstr += FilterTranslator.ruleSql(ref parameters1); IList users = new List(); Int64 totalcount = 0; //跨库 获取存储上下限 //IList limits = new List(); IList limits = PushRecordDAL.GetPushLimit(); if (limits.Count > 0) { //List superior_list = new List(0); Dictionary gapnum = new Dictionary(); //foreach (PushStorLimit limit in limits) //{ // //Role role; // //if (roleMap.TryGetValue(permsr.RoleId, out role)) // //{ // // listRoles.Add(role); // //} // superior_list.Add(limit.GoodsId); // gapnum.Add(limit.GoodsId, limit); //} ////perms.RoleList = listRoles; //string limitss = string.Join("','", superior_list.ToArray()); string commandText0 = "select * from ( select *, row_number() over (order by ContactCode " + direct + " ) as rownum "; string commandText1 = ""; //string commandText1 = "" + // " FROM(SELECT ROW_NUMBER() OVER(PARTITION BY t1.GoodsId ORDER BY t1.LastPrice asc,t1.SysDates1 asc) AS RNUM," +//,t1.ContactId // " * " + // "FROM sup_PushContactWithGoods t1" + // " WHERE 1=1 " + // //" and exists(" + // //" select 1 from LJHYBZK.dbo.sup_PushStorLimit A " + // //" where A.GoodsId = t1.GoodsId)" + // " and t1.GoodsId IN ('" + // limitss + // " ')" + // filterstr + // ") AS T " + // " WHERE T.RNUM = 1"; string commandText2 = ")AAA where AAA.rownum>" + start + " and AAA.rownum<" + end + " "; //string commandText = commandText0 + commandText1 + commandText2; //bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result); //// 把DataTable转换为IList //if (dt != null && dt.Rows.Count > 0) //{ // // 把DataTable转换为IList // users = ModelConvertHelper.ConvertToModel(dt); // foreach (PushContactWithGoods user in users) // { // //Role role; // //if (roleMap.TryGetValue(permsr.RoleId, out role)) // //{ // // listRoles.Add(role); // //} // PushStorLimit StorLimit; // gapnum.TryGetValue(user.GoodsId, out StorLimit); // user.StoreGapNum = StorLimit.StoreGapNum; // user.EntId = StorLimit.EntId; // user.PurchaseTotalNum = StorLimit.PurchaseTotalNum;//StoreGapNum // } //} #endregion users = ContactBAL.GetPushContactWithGoods(filterstr,null, limits,out gapnum,out commandText1,false, commandText0, commandText2, parameters1.ToArray()); foreach (PushContactWithGoods user in users) { //Role role; //if (roleMap.TryGetValue(permsr.RoleId, out role)) //{ // listRoles.Add(role); //} PushStorLimit StorLimit; gapnum.TryGetValue(user.GoodsId, out StorLimit); user.StoreGapNum = StorLimit.StoreGapNum; user.EntId = StorLimit.EntId; user.PurchaseTotalNum = StorLimit.PurchaseTotalNum;//StoreGapNum } string resultrow; string commandTextRowCount = "select count(*) " + commandText1; //totalcount = DataAccess.GetRowCountDefine(connectstr, commandTextRowCount, out resultrow); totalcount = DataAccess.GetRowCountDefine(commandTextRowCount, parameters1.ToArray(), out resultrow); } IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; var jsonData = JsonConvert.SerializeObject(users, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, totalCount = totalcount }); } ////待推送联系人--所有推送的业务员,查询业务员的推送记录 [AuthPermission] [HttpGet, Route("getcontacts")] public JsonResult GetContacts(string GoodsId) { IList users = new List(); DataTable dt = new DataTable(); string result = string.Empty; if (GoodsId == null || GoodsId == "") { return Json(new String[] { ""}); } GoodsId = GoodsId.Replace(",","','"); //跨库 获取存储上下限 IList limits = new List();//PushRecordDAL.GetPushLimit(" and GoodsId in ('"+GoodsId+"')"); //if (limits.Count > 0) //{ List superior_list = new List(0); Dictionary gapnum = new Dictionary(); users = ContactBAL.GetPushContactWithGoods(" and GoodsId in ('" + GoodsId + "') ", ",t1.ContactId,t1.SuppliersId", limits,out gapnum, out _); //} IList