package cn.stylefeng.guns.modular.business.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.date.DateUtil;
|
import cn.stylefeng.guns.modular.business.dto.request.MentalAnalysisSpecialTimeConfigEdit2Request;
|
import cn.stylefeng.guns.modular.business.entity.MentalAnalysisSpecialTimeConfig;
|
import cn.stylefeng.guns.modular.business.entity.MentalAppointment;
|
import cn.stylefeng.guns.modular.business.mapper.MentalAnalysisSpecialTimeConfigMapper;
|
import cn.stylefeng.guns.modular.business.service.IMentalAnalysisSpecialTimeConfigService;
|
import cn.stylefeng.guns.modular.business.service.IMentalAppointmentService;
|
import cn.stylefeng.roses.kernel.rule.enums.MentalAppointmentStatusEnum;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ErrorResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.jetbrains.annotations.Nullable;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 性格分析特殊时间配置 服务实现类
|
* </p>
|
*
|
* @author goupan
|
* @since 2024-01-26
|
*/
|
@Service
|
public class MentalAnalysisSpecialTimeConfigServiceImpl extends ServiceImpl<MentalAnalysisSpecialTimeConfigMapper, MentalAnalysisSpecialTimeConfig> implements IMentalAnalysisSpecialTimeConfigService {
|
|
@Resource
|
private IMentalAppointmentService mentalAppointmentService;
|
|
@Transactional(rollbackFor = Exception.class)
|
@Override
|
public ResponseData editSpecialTimeConfig(MentalAnalysisSpecialTimeConfigEdit2Request req) {
|
List<MentalAnalysisSpecialTimeConfig> batchSpecialTimeConfigList = new ArrayList<>();
|
|
// 转日期格式
|
Date specialDayDate = DateUtil.parseDate(req.getSpecialDay());
|
|
// 判断是设置当天、还是指定时间段
|
if (req.getSpecialTimeConfigList() == null || req.getSpecialTimeConfigList().size() == 0) {
|
// 获取当天预约(服务中)
|
Long inServiceMentalAppointmentCount = mentalAppointmentService.count(
|
Wrappers.<MentalAppointment>lambdaQuery()
|
.eq(MentalAppointment::getWorkerId, req.getCounsellingInfoId())
|
.eq(MentalAppointment::getAppointmentDay, req.getSpecialDay())
|
.eq(MentalAppointment::getStatusFlag, MentalAppointmentStatusEnum.IN_SERVICE.getCode())
|
);
|
if (inServiceMentalAppointmentCount > 0) {
|
return new ErrorResponseData("500", "当天有预约服务中,设置特殊时段失败!");
|
}
|
|
// 获取当天预约(待服务)
|
List<MentalAppointment> todayMentalAppointmentList = mentalAppointmentService.list(
|
Wrappers.<MentalAppointment>lambdaQuery()
|
.eq(MentalAppointment::getWorkerId, req.getCounsellingInfoId())
|
.eq(MentalAppointment::getAppointmentDay, req.getSpecialDay())
|
.eq(MentalAppointment::getStatusFlag, MentalAppointmentStatusEnum.WAIT_SERVICE.getCode())
|
);
|
// 预约单新分配性格分析师
|
ResponseData x = updateMentalAppointmentNewWorkerOperation(todayMentalAppointmentList);
|
if (x != null) {
|
return x;
|
}
|
|
// 设置当天
|
MentalAnalysisSpecialTimeConfig o = BeanUtil.toBean(req, MentalAnalysisSpecialTimeConfig.class);
|
o.setIsCancelDay(1);
|
o.setCounsellingInfoId(req.getCounsellingInfoId());
|
o.setSpecialDay(specialDayDate);
|
batchSpecialTimeConfigList.add(o);
|
} else {
|
// 特殊时间段,是否未覆盖预约时间
|
List<MentalAppointment> todayMentalAppointmentList = mentalAppointmentService.list(
|
Wrappers.<MentalAppointment>lambdaQuery()
|
.eq(MentalAppointment::getWorkerId, req.getCounsellingInfoId())
|
.eq(MentalAppointment::getAppointmentDay, req.getSpecialDay())
|
.in(MentalAppointment::getStatusFlag, Arrays.asList(
|
MentalAppointmentStatusEnum.WAIT_SERVICE.getCode(),
|
MentalAppointmentStatusEnum.IN_SERVICE.getCode()
|
))
|
.and(wand ->
|
req.getSpecialTimeConfigList().forEach(st -> {
|
wand.or(wor -> wor.ne(MentalAppointment::getBeginTimePoint, st.getSpecialBeginTimePoint())
|
.ne(MentalAppointment::getEndTimePoint, st.getSpecialEndTimePoint()));
|
})
|
)
|
);
|
// 服务中存在,未覆盖,提示失败
|
Boolean inServicePresent = todayMentalAppointmentList.stream().filter(tma -> MentalAppointmentStatusEnum.IN_SERVICE.getCode().equals(tma.getStatusFlag())).findAny().isPresent();
|
if (inServicePresent) {
|
return new ErrorResponseData("500", "有预约服务中,设置特殊时段失败!");
|
}
|
|
// 预约单新分配性格分析师
|
ResponseData x = updateMentalAppointmentNewWorkerOperation(todayMentalAppointmentList);
|
if (x != null) {
|
return x;
|
}
|
|
// 设置时间段特殊时间
|
for (MentalAnalysisSpecialTimeConfigEdit2Request.SpecialTimeConfig t : req.getSpecialTimeConfigList()) {
|
MentalAnalysisSpecialTimeConfig o = BeanUtil.toBean(t, MentalAnalysisSpecialTimeConfig.class);
|
o.setCounsellingInfoId(req.getCounsellingInfoId());
|
o.setSpecialDay(specialDayDate);
|
batchSpecialTimeConfigList.add(o);
|
}
|
}
|
|
// 清除当天的设置
|
this.remove(
|
Wrappers.<MentalAnalysisSpecialTimeConfig>lambdaQuery()
|
.eq(MentalAnalysisSpecialTimeConfig::getCounsellingInfoId, req.getCounsellingInfoId())
|
.eq(MentalAnalysisSpecialTimeConfig::getSpecialDay, req.getSpecialDay())
|
);
|
|
if (CollUtil.isNotEmpty(batchSpecialTimeConfigList)) {
|
this.saveOrUpdateBatch(batchSpecialTimeConfigList);
|
}
|
return new SuccessResponseData();
|
}
|
|
/**
|
* 预约单新分配性格分析师
|
* @param todayMentalAppointmentList
|
* @return
|
*/
|
@Nullable
|
private ResponseData updateMentalAppointmentNewWorkerOperation(List<MentalAppointment> todayMentalAppointmentList) {
|
if (CollUtil.isNotEmpty(todayMentalAppointmentList)) {
|
// 修改待服务的预约性格分析师
|
List<MentalAppointment> waitUpdateMentalAppointmentList = new ArrayList<>();
|
for (MentalAppointment o : todayMentalAppointmentList) {
|
MentalAppointment newMa = new MentalAppointment();
|
newMa.setId(o.getId());
|
|
// 预约时间匹配性格分析师
|
Long workerId = mentalAppointmentService.assignMentalAppointmentWorkerId(o.getAppointmentDay(), o.getBeginTimePoint(), o.getEndTimePoint());
|
if (workerId == null) {
|
return new ErrorResponseData("500", "新分配性格分析师失败!");
|
}
|
|
// 分配新的性格分析师
|
newMa.setWorkerId(workerId);
|
waitUpdateMentalAppointmentList.add(newMa);
|
}
|
if (CollUtil.isNotEmpty(waitUpdateMentalAppointmentList)) {
|
mentalAppointmentService.updateBatchById(waitUpdateMentalAppointmentList);
|
}
|
}
|
return null;
|
}
|
|
}
|