123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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<int, Role> roleMap = new ConcurrentDictionary<int, Role>();
-
- ///
- /// 业务员产品供应商列表
- [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<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取业务员产品供应商列表
- DataTable dt = new DataTable();
- string result;
- IList<K_Contactsp> permss = new List<K_Contactsp>(0);
- List<SqlParameter> parameters = new List<SqlParameter>();
- 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<K_Contactsp>
- permss = ModelConvertHelper<K_Contactsp>.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<Menu> 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<DataAccessCommand> list = new List<DataAccessCommand>();
- #region 更新记录状态
- string commandTextStateR = "UPDATE K_Contactsp " +
- " SET " +
- " PushFlag = @PushFlag" +
- " WHERE Id = @Id "
- ;
- string resultStateR;
- //准备参数
- List<List<Object>> parametersStateR = new List<List<Object>>();
- parametersStateR.Add(new List<Object>() { "PushFlag", IsPush==0?'N':'Y' });
- parametersStateR.Add(new List<Object>() { "Id", Id });
- List<SqlParameter> 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<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "Id", id });
- string result = "";
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- return Content("{"
- + success
- + "}");
- }
-
- }
- }
|