MarketCustomerResourcesController.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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. [HttpPost]
  29. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  30. public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
  31. {
  32. JsonView jw = new JsonView();
  33. try
  34. {
  35. Result resultData = await _clientDataRepository._Init(dto);
  36. if (resultData.Code == 0)
  37. {
  38. jw = JsonView(true, "查询成功!", resultData.Data);
  39. }
  40. else
  41. {
  42. jw = JsonView(false, resultData.Msg);
  43. }
  44. }
  45. catch (Exception)
  46. {
  47. jw = JsonView(false, "程序错误!");
  48. }
  49. return Ok(jw);
  50. }
  51. /// <summary>
  52. /// 查询客户资料数据
  53. /// </summary>
  54. /// <returns></returns>
  55. [HttpPost]
  56. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  57. public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
  58. {
  59. #region 参数验证
  60. if (dto.OperationUserId < 0)
  61. return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
  62. if (dto.PortType < 0)
  63. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  64. #endregion
  65. JsonView jw = new JsonView();
  66. try
  67. {
  68. Result resultData = await _clientDataRepository.QueryNewClientData(dto);
  69. if (resultData.Code == 0)
  70. {
  71. #region 客户资料表操作记录
  72. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
  73. #endregion
  74. jw = JsonView(true, resultData.Msg, resultData.Data);
  75. }
  76. else
  77. {
  78. jw = JsonView(false, resultData.Msg);
  79. }
  80. }
  81. catch (Exception)
  82. {
  83. jw = JsonView(false, "程序错误!");
  84. }
  85. return Ok(jw);
  86. }
  87. /// <summary>
  88. /// 客户资料数据
  89. /// Details
  90. /// </summary>
  91. /// <returns></returns>
  92. [HttpPost]
  93. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  94. public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
  95. {
  96. #region 参数验证
  97. if (dto.Id < 0)
  98. return Ok(JsonView(false, "请传入有效的Id参数!"));
  99. if (dto.UserId < 0)
  100. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  101. if (dto.PortType < 0)
  102. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  103. #endregion
  104. JsonView jw = new JsonView();
  105. try
  106. {
  107. Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
  108. if (resultData.Code == 0)
  109. {
  110. #region 客户资料表操作记录
  111. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  112. #endregion
  113. jw = JsonView(true, "查询成功!", resultData.Data);
  114. }
  115. else
  116. {
  117. jw = JsonView(false, resultData.Msg);
  118. }
  119. }
  120. catch (Exception)
  121. {
  122. jw = JsonView(false, "程序错误!");
  123. }
  124. return Ok(jw);
  125. }
  126. /// <summary>
  127. /// 客户资料操作(Status:1.新增,2.修改)
  128. /// </summary>
  129. /// <param name="dto"></param>
  130. /// <returns></returns>
  131. [HttpPost]
  132. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  133. public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
  134. {
  135. #region 参数验证
  136. if (dto.CreateUserId < 0)
  137. {
  138. return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
  139. }
  140. if (dto.PortType < 0)
  141. {
  142. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  143. }
  144. #endregion
  145. try
  146. {
  147. Domain.Result result = await _clientDataRepository.NewClientOp(dto);
  148. if (result.Code != 0)
  149. {
  150. return Ok(JsonView(false, result.Msg));
  151. }
  152. #region 客户资料操作记录
  153. OperationEnum operationEnum = OperationEnum.NoOperation;
  154. if (dto.Status == 1)
  155. {
  156. operationEnum = OperationEnum.Add;
  157. dto.Id = Convert.ToInt32(result.Data);
  158. }
  159. else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
  160. await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
  161. #endregion
  162. return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
  163. }
  164. catch (Exception ex)
  165. {
  166. return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
  167. }
  168. }
  169. /// <summary>
  170. /// 新客户资料操作(删除)
  171. /// </summary>
  172. /// <param name="dto"></param>
  173. /// <returns></returns>
  174. [HttpPost]
  175. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  176. public async Task<IActionResult> NewClientDel(DelBaseDto dto)
  177. {
  178. #region 参数验证
  179. if (dto.Id < 0)
  180. {
  181. return Ok(JsonView(false, "请传入有效的Id参数!"));
  182. }
  183. if (dto.DeleteUserId < 0)
  184. {
  185. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  186. }
  187. if (dto.PortType < 0)
  188. {
  189. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  190. }
  191. #endregion
  192. var res = await _clientDataRepository.DelNewClientData(dto);
  193. if (res.Code != 0)
  194. {
  195. return Ok(JsonView(false, "删除失败"));
  196. }
  197. #region 客户资料表操作记录
  198. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
  199. #endregion
  200. return Ok(JsonView(true, "删除成功!"));
  201. }
  202. /// <summary>
  203. /// 获取下拉列表数据和单条数据信息
  204. /// </summary>
  205. /// <param name="dto"></param>
  206. /// <returns></returns>
  207. [HttpPost]
  208. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  209. public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
  210. {
  211. JsonView jw = new JsonView();
  212. var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
  213. if (result.Code == 0)
  214. {
  215. #region 客户资料表操作记录
  216. await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
  217. #endregion
  218. jw = JsonView(true, result.Msg, result.Data);
  219. }
  220. else
  221. {
  222. jw = JsonView(false, result.Msg);
  223. }
  224. return Ok(jw);
  225. }
  226. /// <summary>
  227. /// 获取现有负责人
  228. /// </summary>
  229. /// <returns></returns>
  230. [HttpPost]
  231. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  232. public async Task<IActionResult> QueryUserSelect()
  233. {
  234. try
  235. {
  236. Result resTable = _clientDataRepository.QueryUserSelect();
  237. return Ok(JsonView(true, resTable.Msg, resTable.Data));
  238. }
  239. catch (Exception)
  240. {
  241. return Ok(JsonView(false, "程序错误!"));
  242. }
  243. }
  244. /// <summary>
  245. /// 获取出团数据
  246. /// </summary>
  247. /// <returns></returns>
  248. [HttpPost]
  249. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  250. public async Task<IActionResult> QueryNumberGroups()
  251. {
  252. var result = await _clientDataRepository.QueryNumberGroups();
  253. if (result.Code != 0)
  254. {
  255. return Ok(JsonView(false, result.Msg));
  256. }
  257. return Ok(JsonView(true, result.Msg, result.Data));
  258. }
  259. /// <summary>
  260. /// 新客户资料操作
  261. /// 批量分配
  262. /// </summary>
  263. /// <param name="dto"></param>
  264. /// <returns></returns>
  265. [HttpPost]
  266. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  267. public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
  268. {
  269. #region 参数验证
  270. if (dto.UserId < 0)
  271. {
  272. return Ok(JsonView(false, "请传入有效的UserId参数!"));
  273. }
  274. if (dto.PortType < 0)
  275. {
  276. return Ok(JsonView(false, "请传入有效的PortType参数!"));
  277. }
  278. #endregion
  279. var res = await _clientDataRepository._BatchAssignment(dto);
  280. if (res.Code != 0)
  281. {
  282. return Ok(JsonView(false, res.Msg));
  283. }
  284. return Ok(JsonView(true, "操作成功!"));
  285. }
  286. }
  287. }