diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/TodoServiceClient.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/TodoServiceClient.java new file mode 100644 index 0000000..416e5fd --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/TodoServiceClient.java @@ -0,0 +1,83 @@ +package com.hz.pm.api.external.todo; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import cn.hutool.http.Method; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import com.hz.pm.api.external.todo.dto.AddSingleWkHandleDTO; +import com.hz.pm.api.external.todo.dto.TodoDto; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author 王仁康 + * @date 2024-01-02 16:55:51 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class TodoServiceClient { + + /** + * 外部系统域名 + */ + @Value("${sms.client-url:}") + private String todoUrl; + + // 发送待办 + public static final String TODO_ADD = "/single_wk_handle/addWkhandle"; + + // 完成待办 + public static final String TODO_COMPLETE = "/single_wk_handle/completeHandle"; + + + /** + * 添加待办方法 + * @param addSingleWkHandleDTO + * @return 接口返回待办ID + */ + public TodoDto addTodo(AddSingleWkHandleDTO addSingleWkHandleDTO) { + String url = todoUrl + TODO_ADD; + Map map = new HashMap<>(); + JSONObject json = (JSONObject) JSONObject.toJSON(addSingleWkHandleDTO.getParams()); + String jsonString = JSON.toJSONString(json); + map.put("params", jsonString); + map.put("wkContent",addSingleWkHandleDTO.getWkContent()); + map.put("wkType",addSingleWkHandleDTO.getWkType()); + map.put("wkUser",addSingleWkHandleDTO.getWkUser()); + String responseResult = HttpUtil.post(url, JSON.toJSONString(map)); + TodoDto todoDto = JSON.parseObject(responseResult, new TypeReference() { + }); +// return JSON.parseObject(responseResult, new TypeReference>() { +// }).get("data"); + return todoDto; + } + + /** + * 完成待办 + * @param wkhandleId 待办ID + */ + public TodoDto completeTodo(String wkhandleId){ + String url = todoUrl + TODO_COMPLETE; + HashMap map = new HashMap<>(); + map.put("wkhandleId",wkhandleId); + // 发送PUT请求 + HttpRequest request = HttpUtil.createRequest(Method.PUT,url) + .form("wkhandleId",wkhandleId); + HttpResponse response = request.execute(); + String responseBody = response.body(); + TodoDto todoDto = JSON.parseObject(responseBody, new TypeReference() { + }); + return todoDto; + } + + +} \ No newline at end of file diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/dto/AddSingleWkHandleDTO.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/dto/AddSingleWkHandleDTO.java new file mode 100644 index 0000000..5ed6fb2 --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/dto/AddSingleWkHandleDTO.java @@ -0,0 +1,32 @@ +package com.hz.pm.api.external.todo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * @author 王仁康 + * @date 2024-01-02 16:55:51 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AddSingleWkHandleDTO implements Serializable { + + private static final long serialVersionUID = -2067546352159912820L; + + // 待办参数,ObjectJson字符串 + private Object params; + + // 待办内容,默认取待办配置中的 + private String wkContent; + + // 待办类型 + private String wkType; + + // 待办用户 + private String wkUser; + +} diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/dto/TodoDto.java b/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/dto/TodoDto.java new file mode 100644 index 0000000..75cb99f --- /dev/null +++ b/hz-pm-api/src/main/java/com/hz/pm/api/external/todo/dto/TodoDto.java @@ -0,0 +1,23 @@ +package com.hz.pm.api.external.todo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.io.Serializable; + +/** + * @author 王仁康 + * @date 2024-01-02 17:04:09 + */ +@AllArgsConstructor +@Data +public class TodoDto implements Serializable { + + private static final long serialVersionUID = 241303725133613373L; + + private Integer code; + + private String msg; + + private String data; +}