日历对接

This commit is contained in:
zhangchenbiao
2023-06-14 10:44:55 +08:00
parent 00c535d950
commit 2ed2296a82
11 changed files with 423 additions and 21 deletions

View File

@@ -0,0 +1,92 @@
package com.cool.store.exception;
import com.cool.store.enums.ErrorCodeEnum;
import lombok.Data;
import java.text.MessageFormat;
/**
* @Description 业务异常类返回
* @author Aaron
* @date 2019/12/20
*/
@Data
public class ApiException extends Exception{
private static final long serialVersionUID = -5068776742356414959L;
/**
* 返回码
*/
private Integer errorCode;
/**
* 返回信息
*/
private String errorMessage;
private Object data;
/**
* 构造函数
* @param errorCode
* @param errorMessage
*/
@Deprecated
public ApiException(Integer errorCode, String errorMessage) {
super(errorMessage);
this.errorCode = errorCode;
this.errorMessage = errorMessage;
}
/**
* 构造函数
* @param errorCode
* @param errorMessage
*/
@Deprecated
public ApiException(Integer errorCode, String errorMessage, Object data) {
super(errorMessage);
this.errorCode = errorCode;
this.errorMessage = errorMessage;
this.data = data;
}
/**
* 构造函数
* @param errorMessage
*/
public ApiException(String errorMessage) {
super(errorMessage);
this.errorMessage = errorMessage;
}
/**
* 构造函数
* @param errorCode
* @param errorMessage
* @param cause
*/
@Deprecated
public ApiException(Integer errorCode, String errorMessage, Throwable cause) {
super(errorMessage, cause);
this.errorCode = errorCode;
this.errorMessage = errorMessage;
}
public ApiException(ErrorCodeEnum responseEnum) {
super(responseEnum.getMessage());
this.errorCode = responseEnum.getCode();
this.errorMessage = responseEnum.getMessage();
}
public ApiException(ErrorCodeEnum responseEnum, Object... objects) {
super(responseEnum.getMessage());
String message = MessageFormat.format(responseEnum.getMessage(), objects);
this.errorCode = responseEnum.getCode();
this.errorMessage = message;
}
}

View File

@@ -0,0 +1,33 @@
package com.cool.store.dto.calendar;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zhangchenbiao
* @FileName: CreateCalendarEventDTO
* @Description: 创建用户日程到用户主日历
* @date 2023-06-13 14:09
*/
@Data
public class CreateCalendarEventDTO {
@ApiModelProperty("发起人")
private String userId;
@ApiModelProperty("日程标题")
private String summary;
@ApiModelProperty("开始时间")
private Long startTime;
@ApiModelProperty("截止时间")
private Long endTime;
@ApiModelProperty("参与者")
private List<String> joinUserIds;
}

View File

@@ -0,0 +1,24 @@
package com.cool.store.dto.calendar;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author zhangchenbiao
* @FileName: DeleteCalendarEventDTO
* @Description:
* @date 2023-06-13 15:02
*/
@Data
public class DeleteCalendarEventDTO {
@ApiModelProperty("发起人id")
private String userId;
@ApiModelProperty("日历id")
private String calendarId;
@ApiModelProperty("事件id")
private String eventId;
}

View File

@@ -0,0 +1,39 @@
package com.cool.store.dto.calendar;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author zhangchenbiao
* @FileName: CreateCalendarEventDTO
* @Description: 创建用户日程到用户主日历
* @date 2023-06-13 14:09
*/
@Data
public class UpdateCalendarEventDTO {
@ApiModelProperty("发起人id")
private String userId;
@ApiModelProperty("日历id")
private String calendarId;
@ApiModelProperty("事件id")
private String eventId;
@ApiModelProperty("日程标题")
private String summary;
@ApiModelProperty("开始时间")
private Long startTime;
@ApiModelProperty("截止时间")
private Long endTime;
@ApiModelProperty("参与者")
private List<String> joinUserIds;
}

View File

@@ -0,0 +1,37 @@
package com.cool.store.dto.calendar;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author zhangchenbiao
* @FileName: UserCalendarsEventVO
* @Description:
* @date 2023-06-13 11:18
*/
@Data
public class UserCalendarsEventDTO {
@ApiModelProperty("日历id")
private String calendarId;
@ApiModelProperty("日程id")
private String eventId;
@ApiModelProperty("日程标题")
private String summary;
@ApiModelProperty("开始时间")
private Long startTime;
@ApiModelProperty("截止时间")
private Long endTime;
public UserCalendarsEventDTO(String calendarId, String eventId, String summary, Long startTime, Long endTime) {
this.calendarId = calendarId;
this.eventId = eventId;
this.summary = summary;
this.startTime = startTime;
this.endTime = endTime;
}
}

View File

@@ -0,0 +1,22 @@
package com.cool.store.dto.calendar;
import lombok.Data;
/**
* @author zhangchenbiao
* @FileName: UserFreeBusyList
* @Description:
* @date 2023-06-13 10:06
*/
@Data
public class UserFreeBusyInfoDTO {
private Long startTime;
private Long endTime;
public UserFreeBusyInfoDTO(long startTime, long endTime) {
this.startTime = startTime;
this.endTime = endTime;
}
}

View File

@@ -0,0 +1,25 @@
package com.cool.store.response.error;
/**
* @author zhangchenbiao
* @FileName: ErrorResponse
* @Description:
* @date 2023-06-13 19:43
*/
public class ErrorResponse {
private Integer code;
private String message;
public ErrorResponse(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer getCode() {
return code;
}
public String getMessage() {
return message;
}
}

View File

@@ -0,0 +1,39 @@
package com.cool.store.handler;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.response.error.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* @author zhangchenbiao
* @FileName: CustomExceptionHandler
* @Description: 自定义异常处理
* @date 2023-06-13 19:42
*/
@RestControllerAdvice
public class CustomExceptionHandler {
@ExceptionHandler(value = ServiceException.class)
public ResponseEntity<ErrorResponse> handleCustomException(ServiceException e) {
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(value = ApiException.class)
public ResponseEntity<ErrorResponse> handleCustomException(ApiException e) {
ErrorResponse errorResponse = new ErrorResponse(e.getErrorCode(), e.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(value = Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception e) {
ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage());
return new ResponseEntity<>(errorResponse, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

View File

@@ -1,6 +1,7 @@
package com.cool.store.http; package com.cool.store.http;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cool.store.dto.calendar.*;
import com.cool.store.dto.enterprise.AuthInfoDTO; import com.cool.store.dto.enterprise.AuthInfoDTO;
import com.cool.store.dto.enterprise.AuthScopeDTO; import com.cool.store.dto.enterprise.AuthScopeDTO;
import com.cool.store.dto.enterprise.EnterpriseUserDTO; import com.cool.store.dto.enterprise.EnterpriseUserDTO;
@@ -8,6 +9,8 @@ import com.cool.store.dto.enterprise.SysDepartmentDTO;
import com.cool.store.dto.login.UserIdInfoDTO; import com.cool.store.dto.login.UserIdInfoDTO;
import com.cool.store.dto.response.ResultDTO; import com.cool.store.dto.response.ResultDTO;
import com.cool.store.entity.EnterpriseUserDO; import com.cool.store.entity.EnterpriseUserDO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.mq.util.HttpRestTemplateService; import com.cool.store.mq.util.HttpRestTemplateService;
import com.cool.store.request.EnterpriseUserRequest; import com.cool.store.request.EnterpriseUserRequest;
import com.cool.store.utils.RestTemplateUtil; import com.cool.store.utils.RestTemplateUtil;
@@ -188,28 +191,84 @@ public class ISVHttpRequest {
return null; return null;
} }
public List<EnterpriseUserRequest> getDeptUsers(String deptId) { /**
List<EnterpriseUserDTO> departmentUsers = getDepartmentUsers(deptId); * 获取用户忙闲信息
if (CollectionUtils.isEmpty(departmentUsers)){ * @param userId
return Lists.newArrayList(); * @param startTime 开始时间 毫秒时间戳
} * @param endTime 截止时间 毫秒时间戳
List<EnterpriseUserRequest> userList = Lists.newArrayList(); * @return
for (EnterpriseUserDTO enterpriseUserDTO:departmentUsers) { */
EnterpriseUserDO enterpriseUser = new EnterpriseUserDO(); public List<UserFreeBusyInfoDTO> getFreeBusyList(String userId, long startTime, long endTime) throws ApiException{
enterpriseUser.setCreateTime(new Date()); String url = isvDomain + "/isv/user/getFreeBusyList";
enterpriseUser.setIsAdmin(false); HashMap requestMap = new HashMap();
enterpriseUser.setRemark(enterpriseUserDTO.getRemark()); requestMap.put("userId", userId);
enterpriseUser.setUserId(enterpriseUserDTO.getUserId()); requestMap.put("startTime", startTime);
if (enterpriseUserDTO.getIsLeaderInDepts() != null) { requestMap.put("endTime", endTime);
//enterpriseUser.setIsLeaderInDepts(JSONObject.toJSONString(enterpriseUserDTO.getIsLeaderInDepts())); ResultDTO responseEntity = null;
try {
responseEntity = httpRestTemplateService.getForObject(url, ResultDTO.class, requestMap);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
return JSONObject.parseArray(JSONObject.toJSONString(responseEntity.getData()), UserFreeBusyInfoDTO.class);
} }
EnterpriseUserRequest enterpriseUserRequest = new EnterpriseUserRequest(); } catch (Exception e) {
//enterpriseUserRequest.setEnterpriseUserDO(enterpriseUser); log.info("调用isv出错{}", e);
if (CollectionUtils.isNotEmpty(enterpriseUserDTO.getDepartmentLists())) { throw new ApiException(e.getMessage());
enterpriseUserRequest.setDepartment(JSONObject.toJSONString(enterpriseUserDTO.getDepartmentLists()));
}
userList.add(enterpriseUserRequest);
} }
return userList; return null;
}
/**
* 创建飞书日程
* @param param
* @return
* @throws ApiException
*/
public UserCalendarsEventDTO createUserCalendarEvent(CreateCalendarEventDTO param) throws ApiException{
String url = isvDomain + "/isv/user/createUserCalendarEvent";
ResultDTO responseEntity = null;
try {
responseEntity = httpRestTemplateService.postForObject(url, param, ResultDTO.class);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), UserCalendarsEventDTO.class);
}
} catch (Exception e) {
log.info("调用isv出错{}", e);
throw new ApiException(e.getMessage());
}
return null;
}
public UserCalendarsEventDTO updateUserCalendarEvent(UpdateCalendarEventDTO param) throws ApiException{
String url = isvDomain + "/isv/user/updateUserCalendarEvent";
ResultDTO responseEntity = null;
try {
responseEntity = httpRestTemplateService.postForObject(url, param, ResultDTO.class);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), UserCalendarsEventDTO.class);
}
} catch (Exception e) {
log.info("调用isv出错{}", e);
throw new ApiException(e.getMessage());
}
return null;
}
public UserCalendarsEventDTO deleteUserCalendarEvent(DeleteCalendarEventDTO param) throws ApiException {
String url = isvDomain + "/isv/user/deleteUserCalendarEvent";
ResultDTO responseEntity = null;
try {
responseEntity = httpRestTemplateService.postForObject(url, param, ResultDTO.class);
log.info("url:{}, response:{}", url, JSONObject.toJSONString(responseEntity));
if(Objects.nonNull(responseEntity.getData()) && responseEntity.isSuccess()){
return JSONObject.parseObject(JSONObject.toJSONString(responseEntity.getData()), UserCalendarsEventDTO.class);
}
} catch (Exception e) {
log.info("调用isv出错{}", e);
throw new ApiException(e.getMessage());
}
return null;
} }
} }

View File

@@ -3,6 +3,7 @@ package com.cool.store.service.impl;
import com.cool.store.constants.CommonConstants; import com.cool.store.constants.CommonConstants;
import com.cool.store.dao.*; import com.cool.store.dao.*;
import com.cool.store.dto.buser.UserEventDTO; import com.cool.store.dto.buser.UserEventDTO;
import com.cool.store.dto.calendar.DeleteCalendarEventDTO;
import com.cool.store.dto.enterprise.*; import com.cool.store.dto.enterprise.*;
import com.cool.store.entity.*; import com.cool.store.entity.*;
import com.cool.store.enums.DataSourceEnum; import com.cool.store.enums.DataSourceEnum;

View File

@@ -1,10 +1,16 @@
package com.cool.store.controller; package com.cool.store.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cool.store.dto.calendar.CreateCalendarEventDTO;
import com.cool.store.dto.calendar.DeleteCalendarEventDTO;
import com.cool.store.dto.calendar.UpdateCalendarEventDTO;
import com.cool.store.dto.calendar.UserCalendarsEventDTO;
import com.cool.store.dto.response.ResultDTO;
import com.cool.store.entity.HyOpenAreaInfoDO; import com.cool.store.entity.HyOpenAreaInfoDO;
import com.cool.store.entity.EnterpriseUserDO; import com.cool.store.entity.EnterpriseUserDO;
import com.cool.store.enums.RocketMqTagEnum; import com.cool.store.enums.RocketMqTagEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.mapper.HyOpenAreaInfoMapper; import com.cool.store.mapper.HyOpenAreaInfoMapper;
import com.cool.store.http.ISVHttpRequest; import com.cool.store.http.ISVHttpRequest;
import com.cool.store.mq.producer.SimpleMessageService; import com.cool.store.mq.producer.SimpleMessageService;
@@ -166,4 +172,29 @@ public class TestController {
return ResponseResult.success(); return ResponseResult.success();
} }
@GetMapping("/user/getFreeBusyList")
public ResultDTO<List<UserCalendarsEventDTO>> getFreeBusyList(@RequestParam("userId") String userId, @RequestParam("startTime") long startTime,
@RequestParam("endTime") long endTime) throws ApiException {
log.info("getUserCalendarsEvents : corpId:{}, appType:{}, userId:{}, startTime:{}, endTime:{}", userId, startTime, endTime);
return ResultDTO.successResult(isvHttpRequest.getFreeBusyList(userId, startTime, endTime));
}
@PostMapping("/user/createUserCalendarEvent")
public ResultDTO<UserCalendarsEventDTO> createUserCalendarEvent(@RequestBody CreateCalendarEventDTO param) throws ApiException {
log.info("createUserCalendarEvent , param:{}", JSONObject.toJSONString(param));
return ResultDTO.successResult(isvHttpRequest.createUserCalendarEvent(param));
}
@PostMapping("/user/updateUserCalendarEvent")
public ResultDTO<UserCalendarsEventDTO> updateUserCalendarEvent(@RequestBody UpdateCalendarEventDTO param) throws ApiException {
log.info("updateUserCalendarEvent , param:{}", JSONObject.toJSONString(param));
return ResultDTO.successResult(isvHttpRequest.updateUserCalendarEvent(param));
}
@PostMapping("/user/deleteUserCalendarEvent")
public ResultDTO<UserCalendarsEventDTO> deleteUserCalendarEvent(@RequestBody DeleteCalendarEventDTO param) throws ApiException {
log.info("createUserCalendarEvent , param:{}", JSONObject.toJSONString(param));
return ResultDTO.successResult(isvHttpRequest.deleteUserCalendarEvent(param));
}
} }