KContactController.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using JCSoft.WX.Framework.Api;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Http;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Threading.Tasks;
  8. using Common.Wechat;
  9. using Common;
  10. using System.Data;
  11. using Common.Model;
  12. using ZcPeng.PublicLibrary;
  13. using CoreEntity.Entity;
  14. using CoreEntity.DAL;
  15. using System.Collections.Concurrent;
  16. using Newtonsoft.Json.Converters;
  17. using Newtonsoft.Json;
  18. using System.Data.SqlClient;
  19. using Microsoft.Extensions.Primitives;
  20. using Microsoft.Extensions.Caching.Memory;
  21. using Jwt;
  22. using PublicLibrary.Model;
  23. using Newtonsoft.Json.Linq;
  24. using SupplierWeb.Codes.mvc;
  25. using SupplierWeb.Codes.Auth;
  26. namespace SupplierWeb.Controllers
  27. {
  28. [Route("web/kcontact")]
  29. public class K_ContactspController : BaseController
  30. {
  31. public K_ContactspController(IMemoryCache cache, IApiClient client) : base(cache, client)
  32. {
  33. }
  34. private ConcurrentDictionary<int, Role> roleMap = new ConcurrentDictionary<int, Role>();
  35. ///
  36. /// 业务员产品供应商列表
  37. [AuthPermission]
  38. [HttpPost, Route("index")]
  39. public JsonResult index(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
  40. string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
  41. {
  42. string LoginAccountId = getStaff("userid");
  43. string RoleId = getStaff("roleid");
  44. //判断参数是否合法
  45. if (string.IsNullOrEmpty(LoginAccountId))
  46. {
  47. return Json(new
  48. {
  49. items = new string[] { },
  50. sum = new { },
  51. totalCount = 0
  52. });
  53. }
  54. string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
  55. if (data != null)
  56. {
  57. //Newtonsoft.Json.Linq.JArray
  58. filters = data.filters.ToObject<QueryFilter[]>();
  59. pageIndex = data.pageIndex;
  60. pageSize = data.pageSize;
  61. sortField = data.sortField;
  62. sortDirection = data.sortDirection;
  63. sumFields = data.sumFields.ToObject<string[]>();
  64. }
  65. #region 获取业务员产品供应商列表
  66. DataTable dt = new DataTable();
  67. string result;
  68. IList<K_Contactsp> permss = new List<K_Contactsp>(0);
  69. List<SqlParameter> parameters = new List<SqlParameter>();
  70. string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new K_Contactsp(),"A.");
  71. filterstr = filterstr.Replace("A.Contact", "B.Contact");
  72. filterstr = filterstr.Replace("A.SuppliersName", "C.BusinessName");
  73. filterstr = filterstr.Replace("A.GoodsName", "D.GoodsName");
  74. filterstr = filterstr.Replace("A.GoodsCode", "D.GoodsCode");
  75. filterstr = filterstr.Replace("A.StaffName", "E.StaffName");
  76. filterstr = filterstr.Replace("A.IsPush", "CASE A.PushFlag WHEN 'N' THEN 0 ELSE 1 END");
  77. sortField = "A."+sortField;
  78. sortField = sortField.Replace("A.Contact", "B.Contact");
  79. sortField = sortField.Replace("A.SuppliersName", "C.BusinessName");
  80. sortField = sortField.Replace("A.GoodsName", "D.GoodsName");
  81. filterstr = filterstr.Replace("A.GoodsCode", "D.GoodsCode");
  82. filterstr = filterstr.Replace("A.StaffName", "E.StaffName");
  83. sortField = sortField.Replace("A.IsPush", "CASE A.PushFlag WHEN 'N' THEN 0 ELSE 1 END");
  84. string direct = " desc ";
  85. if (sortDirection != 1)
  86. direct = " asc";
  87. int start = (pageIndex - 1) * pageSize;
  88. int end = (start + 1 + pageSize);
  89. string commandText0 = "select * from ";
  90. string commandText1 = "(" +
  91. "select A.*,CASE A.PushFlag WHEN 'N' THEN 0 ELSE 1 END AS IsPush," +
  92. "C.BusinessName as SuppliersName,B.Contact,D.GoodsName,D.GoodsCode,E.StaffName,row_number() over" +
  93. "( order by " + sortField + " " + direct + " ) as rownum from " +
  94. "K_Contactsp as A " +
  95. "left join ContactDoc B on B.ContactId = A.ContactId and B.EntId = A.EntId " +
  96. "left join BusinessDoc C on C.BusinessId = B.BusinessId and C.EntId = B.EntId " +
  97. "left join GoodsDoc D on D.GoodsId = A.GoodsId and D.EntId = A.EntId " +
  98. "left join StaffDoc E on E.StaffId = A.SaleManId and E.EntId = A.EntId " +
  99. " where 1=1 " +
  100. //" and A.CreationPerson = '" + userids + "'" +
  101. ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and A.SaleManId = '" + StaffDocId + "' ")) +//只查询当前采购员的联系人
  102. filterstr +
  103. ")AAA ";
  104. string commandText2 = " where AAA.rownum>" + start + " and AAA.rownum<" + end;
  105. bool success = DataAccess.GetValues(commandText0 + commandText1 + commandText2, ref dt, parameters.ToArray(), out result);
  106. #endregion
  107. if (dt != null && dt.Rows.Count > 0)
  108. {
  109. // 把DataTable转换为IList<K_Contactsp>
  110. permss = ModelConvertHelper<K_Contactsp>.ConvertToModel(dt);
  111. }
  112. string result1;
  113. long totalcount = DataAccess.GetRowCountDefine("select count(Id) from " + commandText1, parameters.ToArray(), out result1);
  114. IsoDateTimeConverter timejson = new IsoDateTimeConverter
  115. {
  116. DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  117. };
  118. //IList<Menu> menus = K_Contactsp.Convert(permss);
  119. var jsonData = JsonConvert.SerializeObject(permss, timejson);
  120. return Json(new
  121. {
  122. items = JsonConvert.DeserializeObject(jsonData),
  123. sum = new { },
  124. totalCount = totalcount
  125. });
  126. }
  127. [AuthPermission]
  128. [HttpPost, Route("setpushflag")]
  129. public JsonResult SePushFlag(string staffId, string Id,
  130. [FromBody]dynamic data)
  131. {
  132. string userids;
  133. string LoginAccountId = userids = getStaffUserid(staffId);
  134. //判断参数是否合法
  135. if (string.IsNullOrEmpty(userids))
  136. {
  137. return Json(new
  138. {
  139. success = 0,
  140. msg = "登陆超时",
  141. timeout = 1
  142. });
  143. }
  144. Int32 SalemanAccountId = Convert.ToInt32(userids);
  145. int IsPush = 0;
  146. if (data != null)
  147. {
  148. Id = data.ID;
  149. IsPush = data.IsPush;
  150. }
  151. List<DataAccessCommand> list = new List<DataAccessCommand>();
  152. #region 更新记录状态
  153. string commandTextStateR = "UPDATE K_Contactsp " +
  154. " SET " +
  155. " PushFlag = @PushFlag" +
  156. " WHERE Id = @Id "
  157. ;
  158. string resultStateR;
  159. //准备参数
  160. List<List<Object>> parametersStateR = new List<List<Object>>();
  161. parametersStateR.Add(new List<Object>() { "PushFlag", IsPush==0?'N':'Y' });
  162. parametersStateR.Add(new List<Object>() { "Id", Id });
  163. List<SqlParameter> parametersStateR1 = DataAccess.ToParameters(parametersStateR);
  164. list.Add(new DataAccessCommand(commandTextStateR, parametersStateR1, CommandType.Text, true));
  165. #endregion
  166. bool success = DataAccess.ExecuteBatchCommands(list, out resultStateR);
  167. return Json(new
  168. {
  169. success = success,
  170. result = resultStateR,
  171. });
  172. }
  173. ////删除业务员产品供应商
  174. [AuthPermission]
  175. [HttpPost, Route("delete")]
  176. public ActionResult Delete(string staffId, string id)
  177. {
  178. string userids;
  179. if(staffId == null) {
  180. StringValues oo = Request.Headers["Sso-Token"];
  181. if (oo.Count > 0 && oo.ToArray()[0] != "")
  182. {
  183. staffId = oo.ToArray()[0];
  184. }
  185. }
  186. string LoginAccountId = userids = getStaffUserid(staffId);
  187. //判断参数是否合法
  188. if (string.IsNullOrEmpty(userids))
  189. {
  190. return Json(new
  191. {
  192. success = 0,
  193. msg = "登陆超时",
  194. timeout = 1
  195. });
  196. }
  197. string commandText = "DELETE FROM K_Contactsp WHERE Id = @Id";
  198. //准备参数
  199. List<List<Object>> parameters = new List<List<Object>>();
  200. parameters.Add(new List<Object>() { "Id", id });
  201. string result = "";
  202. List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
  203. int success = DataAccess.ExecuteCommand(commandText, parameters1, out result);
  204. return Content("{"
  205. + success
  206. + "}");
  207. }
  208. }
  209. }