EastarDdController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.malk.eastar.controller;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.malk.eastar.service.DDCoreClient;
  4. import com.malk.server.common.McException;
  5. import com.malk.server.common.McR;
  6. import com.malk.service.dingtalk.DDClient;
  7. import com.malk.service.dingtalk.DDClient_Report;
  8. import com.malk.utils.UtilMap;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. @Slf4j
  18. @RestController
  19. @RequestMapping("/dd")
  20. public class EastarDdController {
  21. @Autowired
  22. private DDClient_Report ddClientReport;
  23. @Autowired
  24. private DDClient ddClient;
  25. @Autowired
  26. private DDCoreClient ddCoreClient;
  27. @PostMapping("/report/create")
  28. public McR createReport(@RequestBody JSONObject param){
  29. log.info("创建日志:{}",param);
  30. McException.assertParamException_Null(param,"template_id","to_chat","dd_from","userid","contents");
  31. JSONObject contents=param.getJSONObject("contents");
  32. List list=new ArrayList();
  33. for(String key:contents.keySet()){
  34. list.add(contents.getJSONObject(key));
  35. }
  36. String result=ddClientReport.createReport(ddClient.getAccessToken(),param.getString("to_userids"),param.getString("to_cids")
  37. ,param.getString("template_id"),param.getBoolean("to_chat"),param.getString("dd_from"),param.getString("userid"),
  38. list);
  39. return McR.success(result);
  40. }
  41. /**
  42. * 根据unionId获取userId
  43. * @param data
  44. * @return
  45. */
  46. // @PostMapping("/getUserIdByUnionId")
  47. McR getUserIdByUnionId(@RequestBody JSONObject data) {
  48. log.info("根据unionId获取userId, {}", data);
  49. McException.assertParamException_Null(data, "unionid");
  50. String unionId = UtilMap.getString(data, "unionid");
  51. try {
  52. String userId = ddCoreClient.getUserIdByUnionId(unionId);
  53. return McR.success(userId);
  54. } catch (Exception e) {
  55. return McR.error("400",e.getMessage());
  56. }
  57. }
  58. /**
  59. * 根据userId获取unionId
  60. * @param data
  61. * @return
  62. */
  63. // @PostMapping("/getUnionIdByUserId")
  64. McR getUnionIdByUserId(@RequestBody JSONObject data) {
  65. log.info("根据userId获取unionId, {}", data);
  66. McException.assertParamException_Null(data, "userid");
  67. String userId = UtilMap.getString(data, "userid");
  68. try {
  69. String unionId = ddCoreClient.getUnionIdByUserId(userId);
  70. return McR.success(unionId);
  71. } catch (Exception e) {
  72. return McR.error("400",e.getMessage());
  73. }
  74. }
  75. /**
  76. * 根据userId获取部门ID
  77. * @param data
  78. * @return
  79. */
  80. // @PostMapping("/getDeptIdListByUserId")
  81. McR getDeptIdListByUserId(@RequestBody JSONObject data) {
  82. log.info("根据userId获取部门ID, {}", data);
  83. McException.assertParamException_Null(data, "userid");
  84. String userId = UtilMap.getString(data, "userid");
  85. try {
  86. List deptIdList = ddCoreClient.getDeptIdListByUserId(userId);
  87. return McR.success(deptIdList);
  88. } catch (Exception e) {
  89. return McR.error("400",e.getMessage());
  90. }
  91. }
  92. }