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 Common.Model; using ZcPeng.PublicLibrary; using CoreEntity.Entity; using CoreEntity.DAL; using System.Collections.Concurrent; using Newtonsoft.Json.Converters; using Newtonsoft.Json; using System.Data.SqlClient; using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Caching.Memory; using Jwt; using PublicLibrary.Model; using Newtonsoft.Json.Linq; using SupplierWeb.Codes.mvc; using SupplierWeb.Codes.Auth; namespace SupplierWeb.Controllers { [Route("web/kcontact")] public class K_ContactspController : BaseController { public K_ContactspController(IMemoryCache cache, IApiClient client) : base(cache, client) { } private ConcurrentDictionary roleMap = new ConcurrentDictionary(); /// /// 业务员产品供应商列表 [AuthPermission] [HttpPost, Route("index")] public JsonResult index(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 }); } string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId); 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; IList permss = new List(0); List parameters = new List(); string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new K_Contactsp(),"A."); filterstr = filterstr.Replace("A.Contact", "B.Contact"); filterstr = filterstr.Replace("A.SuppliersName", "C.BusinessName"); filterstr = filterstr.Replace("A.GoodsName", "D.GoodsName"); filterstr = filterstr.Replace("A.GoodsCode", "D.GoodsCode"); filterstr = filterstr.Replace("A.StaffName", "E.StaffName"); filterstr = filterstr.Replace("A.IsPush", "CASE A.PushFlag WHEN 'N' THEN 0 ELSE 1 END"); sortField = "A."+sortField; sortField = sortField.Replace("A.Contact", "B.Contact"); sortField = sortField.Replace("A.SuppliersName", "C.BusinessName"); sortField = sortField.Replace("A.GoodsName", "D.GoodsName"); filterstr = filterstr.Replace("A.GoodsCode", "D.GoodsCode"); filterstr = filterstr.Replace("A.StaffName", "E.StaffName"); sortField = sortField.Replace("A.IsPush", "CASE A.PushFlag WHEN 'N' THEN 0 ELSE 1 END"); string direct = " desc "; if (sortDirection != 1) direct = " asc"; int start = (pageIndex - 1) * pageSize; int end = (start + 1 + pageSize); string commandText0 = "select * from "; string commandText1 = "(" + "select A.*,CASE A.PushFlag WHEN 'N' THEN 0 ELSE 1 END AS IsPush," + "C.BusinessName as SuppliersName,B.Contact,D.GoodsName,D.GoodsCode,E.StaffName,row_number() over" + "( order by " + sortField + " " + direct + " ) as rownum from " + "K_Contactsp as A " + "left join ContactDoc B on B.ContactId = A.ContactId and B.EntId = A.EntId " + "left join BusinessDoc C on C.BusinessId = B.BusinessId and C.EntId = B.EntId " + "left join GoodsDoc D on D.GoodsId = A.GoodsId and D.EntId = A.EntId " + "left join StaffDoc E on E.StaffId = A.SaleManId and E.EntId = A.EntId " + " where 1=1 " + //" and A.CreationPerson = '" + userids + "'" + ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and A.SaleManId = '" + StaffDocId + "' ")) +//只查询当前采购员的联系人 filterstr + ")AAA "; string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end; bool success = DataAccess.GetValues(commandText0 + commandText1 + commandText2, ref dt, parameters.ToArray(), out result); #endregion if (dt != null && dt.Rows.Count > 0) { // 把DataTable转换为IList permss = ModelConvertHelper.ConvertToModel(dt); } string result1; long totalcount = DataAccess.GetRowCountDefine("select count(Id) from " + commandText1, parameters.ToArray(), out result1); IsoDateTimeConverter timejson = new IsoDateTimeConverter { DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; //IList menus = K_Contactsp.Convert(permss); var jsonData = JsonConvert.SerializeObject(permss, timejson); return Json(new { items = JsonConvert.DeserializeObject(jsonData), sum = new { }, totalCount = totalcount }); } [AuthPermission] [HttpPost, Route("setpushflag")] public JsonResult SePushFlag(string staffId, string Id, [FromBody]dynamic data) { string userids; string LoginAccountId = userids = getStaffUserid(staffId); //判断参数是否合法 if (string.IsNullOrEmpty(userids)) { return Json(new { success = 0, msg = "登陆超时", timeout = 1 }); } Int32 SalemanAccountId = Convert.ToInt32(userids); int IsPush = 0; if (data != null) { Id = data.ID; IsPush = data.IsPush; } List list = new List(); #region 更新记录状态 string commandTextStateR = "UPDATE K_Contactsp " + " SET " + " PushFlag = @PushFlag" + " WHERE Id = @Id " ; string resultStateR; //准备参数 List> parametersStateR = new List>(); parametersStateR.Add(new List() { "PushFlag", IsPush==0?'N':'Y' }); parametersStateR.Add(new List() { "Id", Id }); List parametersStateR1 = DataAccess.ToParameters(parametersStateR); list.Add(new DataAccessCommand(commandTextStateR, parametersStateR1, CommandType.Text, true)); #endregion bool success = DataAccess.ExecuteBatchCommands(list, out resultStateR); return Json(new { success = success, result = resultStateR, }); } ////删除业务员产品供应商 [AuthPermission] [HttpPost, Route("delete")] public ActionResult Delete(string staffId, string id) { string userids; if(staffId == null) { StringValues oo = Request.Headers["Sso-Token"]; if (oo.Count > 0 && oo.ToArray()[0] != "") { staffId = oo.ToArray()[0]; } } string LoginAccountId = userids = getStaffUserid(staffId); //判断参数是否合法 if (string.IsNullOrEmpty(userids)) { return Json(new { success = 0, msg = "登陆超时", timeout = 1 }); } string commandText = "DELETE FROM K_Contactsp WHERE Id = @Id"; //准备参数 List> parameters = new List>(); parameters.Add(new List() { "Id", id }); string result = ""; List parameters1 = DataAccess.ToParameters(parameters); int success = DataAccess.ExecuteCommand(commandText, parameters1, out result); return Content("{" + success + "}"); } } }