| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package com.malk.eastar.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.malk.eastar.service.DDCoreClient;
- import com.malk.server.common.McException;
- import com.malk.server.common.McR;
- import com.malk.service.dingtalk.DDClient;
- import com.malk.service.dingtalk.DDClient_Report;
- import com.malk.utils.UtilMap;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.ArrayList;
- import java.util.List;
- @Slf4j
- @RestController
- @RequestMapping("/dd")
- public class EastarDdController {
- @Autowired
- private DDClient_Report ddClientReport;
- @Autowired
- private DDClient ddClient;
- @Autowired
- private DDCoreClient ddCoreClient;
- @PostMapping("/report/create")
- public McR createReport(@RequestBody JSONObject param){
- log.info("创建日志:{}",param);
- McException.assertParamException_Null(param,"template_id","to_chat","dd_from","userid","contents");
- JSONObject contents=param.getJSONObject("contents");
- List list=new ArrayList();
- for(String key:contents.keySet()){
- list.add(contents.getJSONObject(key));
- }
- String result=ddClientReport.createReport(ddClient.getAccessToken(),param.getString("to_userids"),param.getString("to_cids")
- ,param.getString("template_id"),param.getBoolean("to_chat"),param.getString("dd_from"),param.getString("userid"),
- list);
- return McR.success(result);
- }
- /**
- * 根据unionId获取userId
- * @param data
- * @return
- */
- // @PostMapping("/getUserIdByUnionId")
- McR getUserIdByUnionId(@RequestBody JSONObject data) {
- log.info("根据unionId获取userId, {}", data);
- McException.assertParamException_Null(data, "unionid");
- String unionId = UtilMap.getString(data, "unionid");
- try {
- String userId = ddCoreClient.getUserIdByUnionId(unionId);
- return McR.success(userId);
- } catch (Exception e) {
- return McR.error("400",e.getMessage());
- }
- }
- /**
- * 根据userId获取unionId
- * @param data
- * @return
- */
- // @PostMapping("/getUnionIdByUserId")
- McR getUnionIdByUserId(@RequestBody JSONObject data) {
- log.info("根据userId获取unionId, {}", data);
- McException.assertParamException_Null(data, "userid");
- String userId = UtilMap.getString(data, "userid");
- try {
- String unionId = ddCoreClient.getUnionIdByUserId(userId);
- return McR.success(unionId);
- } catch (Exception e) {
- return McR.error("400",e.getMessage());
- }
- }
- /**
- * 根据userId获取部门ID
- * @param data
- * @return
- */
- // @PostMapping("/getDeptIdListByUserId")
- McR getDeptIdListByUserId(@RequestBody JSONObject data) {
- log.info("根据userId获取部门ID, {}", data);
- McException.assertParamException_Null(data, "userid");
- String userId = UtilMap.getString(data, "userid");
- try {
- List deptIdList = ddCoreClient.getDeptIdListByUserId(userId);
- return McR.success(deptIdList);
- } catch (Exception e) {
- return McR.error("400",e.getMessage());
- }
- }
- }
|