MarketCustomerResourcesController.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using OASystem.API.OAMethodLib;
  2. using OASystem.Domain.AesEncryption;
  3. using OASystem.Domain.Dtos.CRM;
  4. using OASystem.Domain.Entities.Customer;
  5. using OASystem.Infrastructure.Repositories.CRM;
  6. using System.Diagnostics;
  7. namespace OASystem.API.Controllers
  8. {
  9. /// <summary>
  10. /// 市场客户资料
  11. /// </summary>
  12. [Route("api/[controller]/[action]")]
  13. public class MarketCustomerResourcesController : ControllerBase
  14. {
  15. private readonly NewClientDataRepository _clientDataRepository;
  16. /// <summary>
  17. /// 初始化
  18. /// </summary>
  19. public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository)
  20. {
  21. this._clientDataRepository = clientDataRepository;
  22. }
  23. /// <summary>
  24. /// 客户资料数据
  25. /// 批量加密
  26. /// </summary>
  27. /// <returns></returns>
  28. [HttpGet]
  29. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30. public async Task<IActionResult> MarketCustomerBatchEncryption()
  31. {
  32. JsonView jw = new JsonView();
  33. var infos = await _clientDataRepository._sqlSugar.Queryable< Crm_NewClientData >().ToListAsync();
  34. Stopwatch stopwatch = Stopwatch.StartNew();
  35. foreach (var info in infos) EncryptionProcessor.EncryptProperties(info);
  36. var updCount = await _clientDataRepository._sqlSugar.Updateable(infos).ExecuteCommandAsync();
  37. stopwatch.Stop();
  38. jw.Count = 200;
  39. jw.Msg = $"AES加密耗时: {stopwatch.ElapsedMilliseconds} 毫秒";
  40. jw.Count = updCount;
  41. return Ok(jw);
  42. }
  43. /// <summary>
  44. /// 客户资料数据
  45. /// 基础数据
  46. /// </summary>
  47. /// <returns></returns>
  48. [HttpPost]
  49. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  50. public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
  51. {
  52. JsonView jw = new JsonView();
  53. try
  54. {
  55. Result resultData = await _clientDataRepository._Init(dto);
  56. if (resultData.Code == 0)
  57. {
  58. jw = JsonView(true, "查询成功!", resultData.Data);
  59. }
  60. else
  61. {
  62. jw = JsonView(false, resultData.Msg);
  63. }
  64. }
  65. catch (Exception)
  66. {
  67. jw = JsonView(false, "程序错误!");
  68. }
  69. return Ok(jw);
  70. }
  71. /// <summary>
  72. /// 查询客户资料数据
  73. /// </summary>
  74. /// <returns></returns>
  75. [HttpPost]
  76. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  77. public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
  78. {
  79. #region 参数验证
  80. if (dto.OperationUserId < 0)
  81. return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  82. if (dto.PortType < 0)
  83. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  84. #endregion
  85. JsonView jw = new JsonView();
  86. try
  87. {
  88. Result resultData = await _clientDataRepository.QueryNewClientData(dto);
  89. if (resultData.Code == 0)
  90. {
  91. #region 客户资料表操作记录
  92. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
  93. #endregion
  94. jw = JsonView(true, resultData.Msg, resultData.Data);
  95. }
  96. else
  97. {
  98. jw = JsonView(false, resultData.Msg);
  99. }
  100. }
  101. catch (Exception)
  102. {
  103. jw = JsonView(false, "程序错误!");
  104. }
  105. return Ok(jw);
  106. }
  107. /// <summary>
  108. /// 客户资料数据
  109. /// Details
  110. /// </summary>
  111. /// <returns></returns>
  112. [HttpPost]
  113. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  114. public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
  115. {
  116. #region 参数验证
  117. if (dto.Id < 0)
  118. return Ok(JsonView(false, "请传入有效的Id参数!"));
  119. if (dto.UserId < 0)
  120. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  121. if (dto.PortType < 0)
  122. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  123. #endregion
  124. JsonView jw = new JsonView();
  125. try
  126. {
  127. Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
  128. if (resultData.Code == 0)
  129. {
  130. #region 客户资料表操作记录
  131. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  132. #endregion
  133. jw = JsonView(true, "查询成功!", resultData.Data);
  134. }
  135. else
  136. {
  137. jw = JsonView(false, resultData.Msg);
  138. }
  139. }
  140. catch (Exception)
  141. {
  142. jw = JsonView(false, "程序错误!");
  143. }
  144. return Ok(jw);
  145. }
  146. /// <summary>
  147. /// 客户资料操作(Status:1.新增,2.修改)
  148. /// </summary>
  149. /// <param name="dto"></param>
  150. /// <returns></returns>
  151. [HttpPost]
  152. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  153. public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
  154. {
  155. #region 参数验证
  156. if (dto.CreateUserId < 0)
  157. {
  158. return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
  159. }
  160. if (dto.PortType < 0)
  161. {
  162. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  163. }
  164. #endregion
  165. try
  166. {
  167. Domain.Result result = await _clientDataRepository.NewClientOp(dto);
  168. if (result.Code != 0)
  169. {
  170. return Ok(JsonView(false, result.Msg));
  171. }
  172. #region 客户资料操作记录
  173. OperationEnum operationEnum = OperationEnum.NoOperation;
  174. if (dto.Status == 1)
  175. {
  176. operationEnum = OperationEnum.Add;
  177. dto.Id = Convert.ToInt32(result.Data);
  178. }
  179. else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
  180. await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
  181. #endregion
  182. return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
  183. }
  184. catch (Exception ex)
  185. {
  186. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  187. }
  188. }
  189. /// <summary>
  190. /// 新客户资料操作(删除)
  191. /// </summary>
  192. /// <param name="dto"></param>
  193. /// <returns></returns>
  194. [HttpPost]
  195. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  196. public async Task<IActionResult> NewClientDel(DelBaseDto dto)
  197. {
  198. #region 参数验证
  199. if (dto.Id < 0)
  200. {
  201. return Ok(JsonView(false, "请传入有效的Id参数!"));
  202. }
  203. if (dto.DeleteUserId < 0)
  204. {
  205. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  206. }
  207. if (dto.PortType < 0)
  208. {
  209. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  210. }
  211. #endregion
  212. var res = await _clientDataRepository.DelNewClientData(dto);
  213. if (res.Code != 0)
  214. {
  215. return Ok(JsonView(false, "删除失败"));
  216. }
  217. #region 客户资料表操作记录
  218. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
  219. #endregion
  220. return Ok(JsonView(true, "删除成功!"));
  221. }
  222. /// <summary>
  223. /// 获取下拉列表数据和单条数据信息
  224. /// </summary>
  225. /// <param name="dto"></param>
  226. /// <returns></returns>
  227. [HttpPost]
  228. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  229. public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
  230. {
  231. JsonView jw = new JsonView();
  232. var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
  233. if (result.Code == 0)
  234. {
  235. #region 客户资料表操作记录
  236. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  237. #endregion
  238. jw = JsonView(true, result.Msg, result.Data);
  239. }
  240. else
  241. {
  242. jw = JsonView(false, result.Msg);
  243. }
  244. return Ok(jw);
  245. }
  246. /// <summary>
  247. /// 获取现有负责人
  248. /// </summary>
  249. /// <returns></returns>
  250. [HttpPost]
  251. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  252. public async Task<IActionResult> QueryUserSelect()
  253. {
  254. try
  255. {
  256. Result resTable = _clientDataRepository.QueryUserSelect();
  257. return Ok(JsonView(true, resTable.Msg, resTable.Data));
  258. }
  259. catch (Exception)
  260. {
  261. return Ok(JsonView(false, "程序错误!"));
  262. }
  263. }
  264. /// <summary>
  265. /// 获取出团数据
  266. /// </summary>
  267. /// <returns></returns>
  268. [HttpPost]
  269. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  270. public async Task<IActionResult> QueryNumberGroups()
  271. {
  272. var result = await _clientDataRepository.QueryNumberGroups();
  273. if (result.Code != 0)
  274. {
  275. return Ok(JsonView(false, result.Msg));
  276. }
  277. return Ok(JsonView(true, result.Msg, result.Data));
  278. }
  279. /// <summary>
  280. /// 新客户资料操作
  281. /// 批量分配
  282. /// </summary>
  283. /// <param name="dto"></param>
  284. /// <returns></returns>
  285. [HttpPost]
  286. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  287. public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
  288. {
  289. #region 参数验证
  290. if (dto.UserId < 0)
  291. {
  292. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  293. }
  294. if (dto.PortType < 0)
  295. {
  296. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  297. }
  298. #endregion
  299. var res = await _clientDataRepository._BatchAssignment(dto);
  300. if (res.Code != 0)
  301. {
  302. return Ok(JsonView(false, res.Msg));
  303. }
  304. return Ok(JsonView(true, "操作成功!"));
  305. }
  306. }
  307. }