diff --git a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java index 4e999dfc3..86502ebf0 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/enums/ErrorCodeEnum.java @@ -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), diff --git a/coolstore-partner-common/src/main/java/com/cool/store/utils/StringUtil.java b/coolstore-partner-common/src/main/java/com/cool/store/utils/StringUtil.java index 017beab97..741a10d69 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/utils/StringUtil.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/utils/StringUtil.java @@ -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; + } + } diff --git a/coolstore-partner-dao/src/main/java/com/cool/store/mapper/HyPartnerInterviewPlanMapper.java b/coolstore-partner-dao/src/main/java/com/cool/store/mapper/HyPartnerInterviewPlanMapper.java index dad3e0347..4501d7963 100644 --- a/coolstore-partner-dao/src/main/java/com/cool/store/mapper/HyPartnerInterviewPlanMapper.java +++ b/coolstore-partner-dao/src/main/java/com/cool/store/mapper/HyPartnerInterviewPlanMapper.java @@ -87,4 +87,11 @@ public interface HyPartnerInterviewPlanMapper { * @return */ InterviewVO getInterviewInfo(String interviewId); + + /** + * 根据条件字段查询面试安排信息 + * @param record + * @return + */ + List selectBySelective(@Param("record") HyPartnerInterviewPlanDO record); } \ No newline at end of file diff --git a/coolstore-partner-dao/src/main/resources/mapper/HyPartnerInterviewPlanMapper.xml b/coolstore-partner-dao/src/main/resources/mapper/HyPartnerInterviewPlanMapper.xml index bb17f44a3..326fd152d 100644 --- a/coolstore-partner-dao/src/main/resources/mapper/HyPartnerInterviewPlanMapper.xml +++ b/coolstore-partner-dao/src/main/resources/mapper/HyPartnerInterviewPlanMapper.xml @@ -298,4 +298,42 @@ left join hy_partner_interview hpi on hpip.id = hpi.interview_plan_id where hpip.id = #{interviewId} + \ No newline at end of file diff --git a/coolstore-partner-model/src/main/java/com/cool/store/request/GetFreeBusyListReq.java b/coolstore-partner-model/src/main/java/com/cool/store/request/GetFreeBusyListReq.java new file mode 100644 index 000000000..8bab12091 --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/request/GetFreeBusyListReq.java @@ -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; +} diff --git a/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/CalendarInfo.java b/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/CalendarInfo.java new file mode 100644 index 000000000..925107d5a --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/CalendarInfo.java @@ -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 freeBusyList; + + public CalendarInfo(Integer dayOfWeek, String year, String month, String day, String dateStr, List 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 getFreeBusyList() { + return freeBusyList; + } + + public void setFreeBusyList(List 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; + } +} diff --git a/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/FreeBusyInfo.java b/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/FreeBusyInfo.java new file mode 100644 index 000000000..745d7f49e --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/FreeBusyInfo.java @@ -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; + } +} \ No newline at end of file diff --git a/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/GetFreeBusyListVO.java b/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/GetFreeBusyListVO.java new file mode 100644 index 000000000..69e400595 --- /dev/null +++ b/coolstore-partner-model/src/main/java/com/cool/store/vo/interview/GetFreeBusyListVO.java @@ -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 calendarList; + +} diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/FeiShuService.java b/coolstore-partner-service/src/main/java/com/cool/store/service/FeiShuService.java new file mode 100644 index 000000000..b2822345b --- /dev/null +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/FeiShuService.java @@ -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; + +} diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/FeiShuServiceImpl.java b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/FeiShuServiceImpl.java new file mode 100644 index 000000000..e488452c9 --- /dev/null +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/FeiShuServiceImpl.java @@ -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 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 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 daySlots = TimeSlotGenerator.generateDaySlots(startTimeStr, endTimeStr); + freeBusyListVO.setCalendarList(daySlots); + + //如果查询结果为空,则直接返回全部时间段都是空闲的 + if (!CollectionUtils.isEmpty(UserFreeBusyInfoList)) { + for (CalendarInfo daySlot : daySlots) { + List 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; + } +} diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/TimeSlotGenerator.java b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/TimeSlotGenerator.java new file mode 100644 index 000000000..0c418a371 --- /dev/null +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/TimeSlotGenerator.java @@ -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 daySlots = generateDaySlots(startDate, endDate); + for (CalendarInfo daySlot : daySlots) { + System.out.println(daySlot); + } + } + + public static List generateDaySlots(String startDate, String endDate) { + List 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 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 generateHourSlots() { + List 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; + } + } +} diff --git a/coolstore-partner-webb/src/main/java/com/cool/store/controller/FeiShuController.java b/coolstore-partner-webb/src/main/java/com/cool/store/controller/FeiShuController.java new file mode 100644 index 000000000..f6f6bea77 --- /dev/null +++ b/coolstore-partner-webb/src/main/java/com/cool/store/controller/FeiShuController.java @@ -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 getFreeBusyList(@RequestBody GetFreeBusyListReq request) throws ApiException { + GetFreeBusyListVO getFreeBusyListVO= feiShuService.getFreeBusyList(request); + return ResponseResult.success(getFreeBusyListVO); + } +}