查询忙闲信息

This commit is contained in:
俞扬
2023-06-17 18:15:25 +08:00
parent a5ae55675a
commit dcb3d1097c
12 changed files with 520 additions and 1 deletions

View File

@@ -60,7 +60,9 @@ public enum ErrorCodeEnum {
INTERVIEW_ENTER_FAIL(1021101, "进入面试间失败", null),
DINGDING_USER_NOT_EXIST(1021102, "用户钉钉信息不存在,无法发起资质审核!", null),
INTERVIEW_NOT_EXIST(1021103, "面试信息不存在!", null),
INTERVIEW_AND_PARTNER_ID_IS_NULL(1021104, "加盟商用户ID和面试官ID不能同时为空", null),
INTERVIEW_PLAN_IS_NULL(1021105, "未查询到相关面试安排!", null),
DATE_PARAMS_IS_ERROR(1021106, "日期参数错误!", null),
SIGN_FAIL(600000, "验签失败", null),
GET_ACCESSTOKEN_ERROR(600001, "获取小程序TOKEN错误", null),
NEW_MOBILE_HAS_EXIST(600002,"加盟商用户信息已存在",null),

View File

@@ -220,4 +220,25 @@ public class StringUtil extends org.apache.commons.lang3.StringUtils {
*/
INT, STRING, ALL;
}
/**
* 左补位
*
* @param str 字符串
* @param length 总位数
* @return Result 补位后的字符串
*/
public static String addZeroForNum(String str, int length) {
int strLen = str.length();
if (strLen < length) {
while (strLen < length) {
StringBuffer sb = new StringBuffer();
sb.append("0").append(str);
str = sb.toString();
strLen++;
}
}
return str;
}
}

View File

@@ -87,4 +87,11 @@ public interface HyPartnerInterviewPlanMapper {
* @return
*/
InterviewVO getInterviewInfo(String interviewId);
/**
* 根据条件字段查询面试安排信息
* @param record
* @return
*/
List<HyPartnerInterviewPlanDO> selectBySelective(@Param("record") HyPartnerInterviewPlanDO record);
}

View File

@@ -298,4 +298,42 @@
left join hy_partner_interview hpi on hpip.id = hpi.interview_plan_id
where hpip.id = #{interviewId}
</select>
<select id="selectBySelective" resultType="com.cool.store.entity.HyPartnerInterviewPlanDO">
select
<include refid="Base_Column_List"/>
from hy_partner_interview_plan
<where>
<if test="record.id !=null and record.id!=''">
and id = #{record.id}
</if>
<if test="record.partnerLineId !=null and record.partnerLineId!=''">
and partner_line_id = #{record.partnerLineId}
</if>
<if test="record.partnerId !=null and record.partnerId!=''">
and partner_id = #{record.partnerId}
</if>
<if test="record.startTime !=null and record.startTime!=''">
and start_time = #{record.startTime}
</if>
<if test="record.endTime !=null and record.endTime!=''">
and end_time = #{record.endTime}
</if>
<if test="record.interviewer !=null and record.interviewer!=''">
and interviewer = #{record.interviewer}
</if>
<if test="record.createTime !=null and record.createTime!=''">
and create_time = #{record.createTime}
</if>
<if test="record.roomId !=null and record.roomId!=''">
and room_id = #{record.roomId}
</if>
<if test="record.roomStatus !=null and record.roomStatus!=''">
and room_status = #{record.roomStatus}
</if>
<if test="record.interviewDate !=null and record.interviewDate!=''">
and interview_date = #{record.interviewDate}
</if>
</where>
</select>
</mapper>

View File

@@ -0,0 +1,21 @@
package com.cool.store.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:08
* @Description:
*/
@Data
@ApiModel
public class GetFreeBusyListReq {
@ApiModelProperty("查询日期")
private String queryDate;
@ApiModelProperty("加盟商用户ID")
private String partnerId;
@ApiModelProperty("面试官ID(如果该字段传了,就查询该面试官的日程忙闲信息,否则查询加盟商对应的面试官的信息)")
private String interviewerId;
}

View File

@@ -0,0 +1,89 @@
package com.cool.store.vo.interview;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:21
* @Description:
*/
@ApiModel(description = "日期列表")
public class CalendarInfo {
@ApiModelProperty("星期几")
private Integer dayOfWeek;
@ApiModelProperty("年份")
private String year;
@ApiModelProperty("月份")
private String month;
@ApiModelProperty("日期")
private String day;
@ApiModelProperty("日期字符串")
private String dateStr;
@ApiModelProperty("飞书日程忙闲清单")
private List<FreeBusyInfo> freeBusyList;
public CalendarInfo(Integer dayOfWeek, String year, String month, String day, String dateStr, List<FreeBusyInfo> freeBusyList) {
this.dayOfWeek = dayOfWeek;
this.year = year;
this.month = month;
this.day = day;
this.dateStr = dateStr;
this.freeBusyList = freeBusyList;
}
public String getDateStr() {
return dateStr;
}
public void setDateStr(String dateStr) {
this.dateStr = dateStr;
}
public List<FreeBusyInfo> getFreeBusyList() {
return freeBusyList;
}
public void setFreeBusyList(List<FreeBusyInfo> freeBusyList) {
this.freeBusyList = freeBusyList;
}
public Integer getDayOfWeek() {
return dayOfWeek;
}
public void setDayOfWeek(Integer dayOfWeek) {
this.dayOfWeek = dayOfWeek;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public String getDay() {
return day;
}
public void setDay(String day) {
this.day = day;
}
}

View File

@@ -0,0 +1,55 @@
package com.cool.store.vo.interview;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:25
* @Description:
*/
@ApiModel(description = "日程忙闲信息")
public class FreeBusyInfo {
@ApiModelProperty("开始时间")
private String startTime;
@ApiModelProperty("结束时间")
private String endTime;
@ApiModelProperty("是否空闲")
private boolean isFree;
public FreeBusyInfo(String startTime, String endTime, boolean isFree) {
this.startTime = startTime;
this.endTime = endTime;
this.isFree = isFree;
}
public FreeBusyInfo(String startTime, String endTime) {
this.startTime = startTime;
this.endTime = endTime;
this.isFree = isFree;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public boolean isFree() {
return isFree;
}
public void setFree(boolean free) {
isFree = free;
}
}

View File

@@ -0,0 +1,21 @@
package com.cool.store.vo.interview;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:19
* @Description:
*/
@ApiModel(description = "日程忙闲信息")
@Data
public class GetFreeBusyListVO {
@ApiModelProperty("日期列表(默认七天,只有请求参数中查询日期不传时才会返回,否则不返回)")
private List<CalendarInfo> calendarList;
}

View File

@@ -0,0 +1,19 @@
package com.cool.store.service;
import com.cool.store.exception.ApiException;
import com.cool.store.http.ISVHttpRequest;
import com.cool.store.request.GetFreeBusyListReq;
import com.cool.store.vo.interview.GetFreeBusyListVO;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:13
* @Description:
*/
public interface FeiShuService {
GetFreeBusyListVO getFreeBusyList(GetFreeBusyListReq request) throws ApiException;
}

View File

@@ -0,0 +1,120 @@
package com.cool.store.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.cool.store.dto.calendar.UserFreeBusyInfoDTO;
import com.cool.store.entity.HyPartnerInterviewPlanDO;
import com.cool.store.enums.ErrorCodeEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.exception.ServiceException;
import com.cool.store.http.ISVHttpRequest;
import com.cool.store.mapper.HyPartnerInterviewPlanMapper;
import com.cool.store.request.GetFreeBusyListReq;
import com.cool.store.service.FeiShuService;
import com.cool.store.vo.interview.CalendarInfo;
import com.cool.store.vo.interview.FreeBusyInfo;
import com.cool.store.vo.interview.GetFreeBusyListVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:13
* @Description:
*/
@Service
public class FeiShuServiceImpl implements FeiShuService {
@Autowired
private ISVHttpRequest isvHttpRequest;
@Autowired
private HyPartnerInterviewPlanMapper hyPartnerInterviewPlanMapper;
@Override
public GetFreeBusyListVO getFreeBusyList(GetFreeBusyListReq request) throws ApiException {
GetFreeBusyListVO freeBusyListVO = new GetFreeBusyListVO();
String queryDate = request.getQueryDate();//查询日期
String partnerId = request.getPartnerId();//加盟商用户ID
String interviewerId = request.getInterviewerId();//面试官ID
//如果加盟商用户ID为空且面试官ID为空返回错误信息
if (StringUtils.isEmpty(partnerId) && StringUtils.isEmpty(interviewerId)) {
throw new ServiceException(ErrorCodeEnum.INTERVIEW_AND_PARTNER_ID_IS_NULL);
}
//如果加盟商用户ID不为空且面试官ID为空
if (StringUtils.isNotEmpty(partnerId) && StringUtils.isEmpty(interviewerId)) {
//根据加盟商用户ID查询面试官ID
HyPartnerInterviewPlanDO hyPartnerInterviewPlanDO = new HyPartnerInterviewPlanDO();
hyPartnerInterviewPlanDO.setPartnerId(partnerId);
List<HyPartnerInterviewPlanDO> hyPartnerInterviewPlanDOS = hyPartnerInterviewPlanMapper.selectBySelective(hyPartnerInterviewPlanDO);
//如果查询结果为空,返回错误信息
if (CollectionUtils.isEmpty(hyPartnerInterviewPlanDOS)) {
throw new ServiceException(ErrorCodeEnum.INTERVIEW_PLAN_IS_NULL);
}
interviewerId = hyPartnerInterviewPlanDOS.get(0).getInterviewer();
}
long startTime = 0L;
long endTime = 0L;
DateTime startDateTime = null;
DateTime endDateTime = null;
//如果查询时间为空,取明天
if (StringUtils.isEmpty(queryDate)) {
startDateTime = DateUtil.beginOfDay(DateUtil.tomorrow());
endDateTime = DateUtil.endOfDay(DateUtil.tomorrow());
} else {
startDateTime = DateUtil.beginOfDay(DateUtil.parse(queryDate));
endDateTime = DateUtil.endOfDay(DateUtil.parse(queryDate));
}
if (startDateTime.isAfter(endDateTime)) {
throw new ServiceException(ErrorCodeEnum.DATE_PARAMS_IS_ERROR);
}
startTime = startDateTime.getTime();
endTime = endDateTime.getTime();
List<UserFreeBusyInfoDTO> UserFreeBusyInfoList = isvHttpRequest.getFreeBusyList(interviewerId, startTime, endTime);
//把startTime和endTime转换成yyyy-MM-dd格式
String startTimeStr = DateUtil.format(startDateTime, "yyyy-MM-dd");
String endTimeStr = DateUtil.format(endDateTime, "yyyy-MM-dd");
List<CalendarInfo> daySlots = TimeSlotGenerator.generateDaySlots(startTimeStr, endTimeStr);
freeBusyListVO.setCalendarList(daySlots);
//如果查询结果为空,则直接返回全部时间段都是空闲的
if (!CollectionUtils.isEmpty(UserFreeBusyInfoList)) {
for (CalendarInfo daySlot : daySlots) {
List<FreeBusyInfo> freeBusyList = daySlot.getFreeBusyList();
for (FreeBusyInfo freeBusyInfo : freeBusyList) {
//把日期和时间拼接成yyyy-MM-dd HH:mm格式
String startStr = daySlot.getDateStr() + " " + freeBusyInfo.getStartTime();
String endStr = daySlot.getDateStr() + " " + freeBusyInfo.getEndTime();
//把yyyy-MM-dd HH:mm格式转换成long类型
long startTimeLong = DateUtil.parse(startStr).getTime();
long endTimeLong = DateUtil.parse(endStr).getTime();
for (UserFreeBusyInfoDTO userFreeBusyInfoDTO : UserFreeBusyInfoList) {
//如果查询结果中的开始时间和结束时间在时间段内,则设置为忙碌
if ((startTimeLong > userFreeBusyInfoDTO.getStartTime() && startTimeLong < userFreeBusyInfoDTO.getStartTime())
|| (endTimeLong > userFreeBusyInfoDTO.getStartTime() && endTimeLong < userFreeBusyInfoDTO.getStartTime())) {
freeBusyInfo.setFree(false);
break;
}
if (endTimeLong <= userFreeBusyInfoDTO.getStartTime()) {
break;
}
}
}
}
}
return freeBusyListVO;
}
}

View File

@@ -0,0 +1,88 @@
package com.cool.store.service.impl;
import cn.hutool.core.date.DateUtil;
import com.cool.store.utils.StringUtil;
import com.cool.store.vo.interview.CalendarInfo;
import com.cool.store.vo.interview.FreeBusyInfo;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class TimeSlotGenerator {
public static void main(String[] args) {
String startDate = "2023-02-27";
String endDate = "2023-03-01";
List<CalendarInfo> daySlots = generateDaySlots(startDate, endDate);
for (CalendarInfo daySlot : daySlots) {
System.out.println(daySlot);
}
}
public static List<CalendarInfo> generateDaySlots(String startDate, String endDate) {
List<CalendarInfo> daySlots = new ArrayList<>();
Date start = DateUtil.parse(startDate);
Date end = DateUtil.parse(endDate);
Calendar startCal = DateUtil.calendar(start);
Calendar endCal = DateUtil.calendar(end);
while (!startCal.after(endCal)) {
int year = startCal.get(Calendar.YEAR);
int month = startCal.get(Calendar.MONTH) + 1;
int day = startCal.get(Calendar.DAY_OF_MONTH);
int dayOfWeek = startCal.get(Calendar.DAY_OF_WEEK);
List<FreeBusyInfo> hourSlots = generateHourSlots();
CalendarInfo daySlot = new CalendarInfo(transDayOfWeek(dayOfWeek),
String.valueOf(year),
StringUtil.addZeroForNum(String.valueOf(month),2),
StringUtil.addZeroForNum(String.valueOf(day),2),
DateUtil.format(startCal.getTime(), "yyyy-MM-dd"),
hourSlots);
daySlots.add(daySlot);
startCal.add(Calendar.DATE, 1);
}
return daySlots;
}
private static List<FreeBusyInfo> generateHourSlots() {
List<FreeBusyInfo> hourSlots = new ArrayList<>();
for (int hour = 10; hour < 17; hour++) {
String startTime = String.format("%02d:00", hour);
String endTime = String.format("%02d:00", hour + 1);
//默认空闲
FreeBusyInfo hourSlot = new FreeBusyInfo(startTime, endTime, true);
hourSlots.add(hourSlot);
}
return hourSlots;
}
public static int transDayOfWeek(int dayOfWeek) {
switch (dayOfWeek) {
case 1:
return 7;
case 2:
return 1;
case 3:
return 2;
case 4:
return 3;
case 5:
return 4;
case 6:
return 5;
case 7:
return 6;
default:
return 0;
}
}
}

View File

@@ -0,0 +1,38 @@
package com.cool.store.controller;
import com.cool.store.exception.ApiException;
import com.cool.store.request.GetFreeBusyListReq;
import com.cool.store.request.GetInterviewListReq;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.FeiShuService;
import com.cool.store.vo.interview.GetFreeBusyListVO;
import com.cool.store.vo.interview.InterviewVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
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.List;
/**
* @Author: young.yu
* @Date: 2023-06-16 13:06
* @Description:
*/
@RestController
@RequestMapping({"/feishu"})
public class FeiShuController {
@Autowired
private FeiShuService feiShuService;
@PostMapping("/calendar/freebusy/list")
@ApiOperation("查询日程忙闲信息")
public ResponseResult<GetFreeBusyListVO> getFreeBusyList(@RequestBody GetFreeBusyListReq request) throws ApiException {
GetFreeBusyListVO getFreeBusyListVO= feiShuService.getFreeBusyList(request);
return ResponseResult.success(getFreeBusyListVO);
}
}