MarketCustomerResourcesController.cs 10 KB

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