package cn.stylefeng.rest.modular.user.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.date.DateField;
|
import cn.hutool.core.date.DateTime;
|
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.BooleanUtil;
|
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.http.HttpUtil;
|
import cn.hutool.json.JSONUtil;
|
import cn.stylefeng.guns.modular.business.dto.*;
|
import cn.stylefeng.guns.modular.business.dto.request.*;
|
import cn.stylefeng.guns.modular.business.entity.*;
|
import cn.stylefeng.guns.modular.business.service.*;
|
import cn.stylefeng.guns.modular.business.service.impl.ImBizService;
|
import cn.stylefeng.rest.ijpay.controller.AliPayController;
|
import cn.stylefeng.rest.ijpay.controller.WxPayController;
|
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
import cn.stylefeng.roses.kernel.customer.api.pojo.CustomerInfo;
|
import cn.stylefeng.roses.kernel.customer.modular.entity.Customer;
|
import cn.stylefeng.roses.kernel.customer.modular.service.CustomerService;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.rule.enums.*;
|
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
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 cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
import cn.stylefeng.roses.kernel.system.modular.role.entity.SysRole;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.stream.Collectors;
|
|
/**
|
* 咨询师信息管理类
|
* @author guo
|
*/
|
@Slf4j
|
@RestController
|
@Api(tags = "咨询师信息")
|
@ApiResource(name = "咨询师信息", resBizType = ResBizTypeEnum.BUSINESS)
|
@RequestMapping
|
public class CounsellingInfoController {
|
|
@Resource
|
private ICounsellingInfoService counsellingInfoService;
|
|
@Resource
|
private ICounsellingTagService counsellingTagService;
|
|
@Resource
|
private ICounsellingSetMealService counsellingSetMealService;
|
|
@Resource
|
private CustomerService customerService;
|
|
@Resource
|
private ICounsellingTimeConfigService counsellingTimeConfigService;
|
|
@Resource
|
private ICounsellingSpecialTimeConfigService counsellingSpecialTimeConfigService;
|
|
@Resource
|
private ICounsellingOrderReservationService counsellingOrderReservationService;
|
|
@Resource
|
private ICounsellingOrderService counsellingOrderService;
|
|
@Resource
|
private IContractRecordService contractRecordService;
|
|
@Resource
|
private ICounsellingReservationWorkService counsellingReservationWorkService;
|
|
@Resource
|
private ImBizService imBizService;
|
|
@Resource
|
private IImGroupService imGroupService;
|
|
@Resource
|
private ICounsellingUserService counsellingUserService;
|
|
@Resource
|
private WxPayController wxPayController;
|
|
@Resource
|
private AliPayController aliPayController;
|
@Resource
|
private IMentalAppointmentService mentalAppointmentService;
|
|
@Value("${refund.alipay-url}")
|
private String refundAlipayUrl;
|
@Value("${refund.wxpay-url}")
|
private String refundWxpayUrl;
|
|
|
|
|
|
|
/**
|
* 获取咨询师信息详情
|
*/
|
@ApiOperation("获取咨询师信息详情")
|
@GetResource(name = "获取咨询师信息详情", path = "/counsellingInfo/detail/{id}", requiredPermission = false)
|
public ResponseData<CounsellinginfoResponseDTO> detail(@PathVariable("id") Long id) {
|
CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(id);
|
//获取课程标签名称
|
LambdaQueryWrapper<CounsellingTag> counsellingTagLambdaQueryWrapper = new QueryWrapper<CounsellingTag>().select(" GROUP_CONCAT(tag_name) tagName ").lambda();
|
Map<String,Object> map = counsellingTagService.getMap(counsellingTagLambdaQueryWrapper.in(CounsellingTag::getId,counsellingInfo.getCounsellingTagIds().split(",")));
|
if (ObjectUtil.isNotEmpty(map)){
|
counsellingInfo.setCounsellingTagNames(map.get("tagName").toString());
|
}
|
//查询套餐信息
|
counsellingInfo.setCounsellingSetMealList(this.counsellingSetMealService.list(new LambdaQueryWrapper<CounsellingSetMeal>().eq(CounsellingSetMeal::getCounsellingInfoId,counsellingInfo.getId()).eq(CounsellingSetMeal::getIsDelete,false)));
|
//根据客户信息
|
Customer customer = this.customerService.getById(counsellingInfo.getUserId());
|
if (customer != null){
|
counsellingInfo.setUserName(customer.getNickName());
|
}
|
//查询是否首次购买
|
CounsellinginfoResponseDTO counsellinginfoResponseDTO = BeanUtil.copyProperties(counsellingInfo, CounsellinginfoResponseDTO.class);
|
counsellinginfoResponseDTO.setWorkStatus(customer.getWorkStatus());
|
counsellinginfoResponseDTO.setCounsellingSetMealList(counsellingInfo.getCounsellingSetMealList());
|
LambdaQueryWrapper<CounsellingOrder> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingOrder>()
|
.eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrder::getStatusFlag,1,2).eq(CounsellingOrder::getCounsellingInfoId,id)
|
.eq(CounsellingOrder::getOrderType,1);
|
long count = this.counsellingOrderService.count(lambdaQueryWrapper);
|
if (count > 0){
|
counsellinginfoResponseDTO.setIsFirstBuy(true);
|
}
|
return new SuccessResponseData<>(counsellinginfoResponseDTO);
|
}
|
|
|
@Resource
|
private CacheOperatorApi<List<CounsellinginfoResponseDTO>> roleInfoCacheApi;
|
|
|
/**
|
* 获取咨询师信息列表(分页)
|
*/
|
@ApiOperation("获取咨询师信息列表(分页)")
|
@GetResource(name = "获取咨询师信息列表(分页)", path = "/counsellingInfo/page")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "searchType", value = "查询类型 1-严选,2-普通查询,默认2", dataTypeClass = Integer.class, paramType = "query")
|
})
|
public ResponseData<List<CounsellinginfoResponseDTO>> page(Integer pageNo, Integer pageSize,Integer searchType) {
|
if (roleInfoCacheApi.get("customer")!=null){
|
List<CounsellinginfoResponseDTO> customer = roleInfoCacheApi.get("customer");
|
return new SuccessResponseData<>(customer);
|
}
|
|
LambdaQueryWrapper<CounsellingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getIsDelete,false)
|
.orderByDesc(CounsellingInfo::getSort,CounsellingInfo::getCreateTime).eq(CounsellingInfo::getListingStatus,1);
|
//默认普通查询
|
if (searchType != null && searchType.intValue() == 1){
|
List<Customer> customerList = customerService.getWorkerListByLineStatusAndPost(null, null, PostIdEnum.PO_22.getCode(), CustomerWorkStatusEnum.ON_WORK.getCode());
|
if (CollectionUtil.isNotEmpty(customerList)){
|
List<Long> customerIds = customerList.stream().map(Customer::getCustomerId).collect(Collectors.toList());
|
lambdaQueryWrapper.in(CounsellingInfo::getUserId,customerIds);
|
}
|
}
|
List<CounsellingInfo> page = this.counsellingInfoService.list(lambdaQueryWrapper);
|
if (CollectionUtil.isNotEmpty(page)){
|
List<Long> counseIds = page.stream().map(CounsellingInfo::getId).collect(Collectors.toList());
|
QueryWrapper<CounsellingOrder> orderQueryWrapper = new QueryWrapper<CounsellingOrder>().select("counselling_info_id counsellingInfoId,count(1) num ");
|
//查询是否首次咨询
|
orderQueryWrapper.lambda().eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrder::getStatusFlag,1,2).in(CounsellingOrder::getCounsellingInfoId,counseIds)
|
.eq(CounsellingOrder::getOrderType,1).groupBy(CounsellingOrder::getCounsellingInfoId).having(" num > 0 ");
|
List<Map<String,Object>> mapList = this.counsellingOrderService.listMaps(orderQueryWrapper);
|
Map<Long,Object> fristMap = new HashMap<>();
|
if (CollectionUtil.isNotEmpty(mapList)){
|
|
mapList.stream().forEach(stringObjectMap -> {
|
fristMap.put(Long.parseLong(stringObjectMap.get("counsellingInfoId").toString()),stringObjectMap.get("num"));
|
});
|
}
|
//查询标签总条数
|
List<CounsellingTag> counsellingTags = this.counsellingTagService.list(new LambdaQueryWrapper<CounsellingTag>()
|
.select(CounsellingTag::getId,CounsellingTag::getTagName));
|
List<Long> custommerIds = page.stream().map(CounsellingInfo::getUserId).collect(Collectors.toList());
|
//查询客户ids
|
List<Customer> customerList = this.customerService.list(new LambdaQueryWrapper<Customer>().select(Customer::getCustomerId,Customer::getNickName).in(Customer::getCustomerId,custommerIds));
|
//查询套餐最低价
|
List<Map<String,Object>> lowMapList = this.counsellingSetMealService.listMaps(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().in(CounsellingSetMeal::getCounsellingInfoId,counseIds)
|
.eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0));
|
|
List<CounsellinginfoResponseDTO> counsellinginfoResponseDTOS = BeanUtil.copyToList(page,CounsellinginfoResponseDTO.class, CopyOptions.create());
|
counsellinginfoResponseDTOS.stream().forEach(counsellinginfoResponseDTO -> {
|
if (fristMap.get(counsellinginfoResponseDTO.getId()) != null){
|
counsellinginfoResponseDTO.setIsFirstBuy(true);
|
}
|
if (StrUtil.isNotBlank(counsellinginfoResponseDTO.getCounsellingTagIds())){
|
List<String> counsellingTagList = Arrays.asList(counsellinginfoResponseDTO.getCounsellingTagIds().split(","));
|
String tagNames = counsellingTags.stream().filter(cou -> counsellingTagList.contains(cou.getId().toString())).map(CounsellingTag::getTagName).collect(Collectors.joining(","));
|
//获取课程标签名称
|
// LambdaQueryWrapper<CounsellingTag> counsellingTagLambdaQueryWrapper = new QueryWrapper<CounsellingTag>().select(" GROUP_CONCAT(tag_name) tagName ").lambda();
|
// Map<String,Object> map = counsellingTagService.getMap(counsellingTagLambdaQueryWrapper.in(CounsellingTag::getId,counsellinginfoResponseDTO.getCounsellingTagIds().split(",")));
|
// if (ObjectUtil.isNotEmpty(map)){
|
counsellinginfoResponseDTO.setCounsellingTagNames(tagNames);
|
// }
|
}
|
counsellinginfoResponseDTO.setPersonalProfile(null);
|
|
counsellinginfoResponseDTO.setNikeName(customerList.stream().filter(cus -> counsellinginfoResponseDTO.getUserId().longValue() == cus.getCustomerId().longValue()).findFirst().get().getNickName());
|
|
// BigDecimal lowPrice = this.counsellingSetMealService.getObj(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().eq(CounsellingSetMeal::getCounsellingInfoId,counsellinginfoResponseDTO.getId())
|
// .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0),Convert::toBigDecimal);
|
|
|
if (CollectionUtil.isNotEmpty(lowMapList)){
|
lowMapList.stream().forEach(stringObjectMap -> {
|
if (stringObjectMap.get("counsellingInfoId") != null){
|
counsellinginfoResponseDTO.setLowPrice(new BigDecimal(stringObjectMap.get("price").toString()));
|
}
|
});
|
if (counsellinginfoResponseDTO.getLowPrice() == null){
|
counsellinginfoResponseDTO.setLowPrice(new BigDecimal(0));
|
}
|
}
|
|
|
});
|
|
|
return new SuccessResponseData<>(counsellinginfoResponseDTOS);
|
}
|
|
return new SuccessResponseData<>();
|
|
|
|
|
|
|
// LambdaQueryWrapper<CounsellingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getIsDelete,false)
|
// .orderByDesc(CounsellingInfo::getSort,CounsellingInfo::getCreateTime).eq(CounsellingInfo::getListingStatus,1);
|
// //默认普通查询
|
// if (searchType != null && searchType.intValue() == 1){
|
// List<Customer> customerList = customerService.getWorkerListByLineStatusAndPost(null, null, PostIdEnum.PO_22.getCode(), CustomerWorkStatusEnum.ON_WORK.getCode());
|
// if (CollectionUtil.isNotEmpty(customerList)){
|
// List<Long> customerIds = customerList.stream().map(Customer::getCustomerId).collect(Collectors.toList());
|
// lambdaQueryWrapper.in(CounsellingInfo::getUserId,customerIds);
|
// }
|
// }
|
// Page<CounsellingInfo> page = this.counsellingInfoService.page(PageFactory.defaultPage(), lambdaQueryWrapper);
|
// if (CollectionUtil.isNotEmpty(page.getRecords())){
|
// List<Long> counseIds = page.getRecords().stream().map(CounsellingInfo::getId).collect(Collectors.toList());
|
// QueryWrapper<CounsellingOrder> orderQueryWrapper = new QueryWrapper<CounsellingOrder>().select("counselling_info_id counsellingInfoId,count(1) num ");
|
// //查询是否首次咨询
|
// orderQueryWrapper.lambda().eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrder::getStatusFlag,1,2).in(CounsellingOrder::getCounsellingInfoId,counseIds)
|
// .eq(CounsellingOrder::getOrderType,1).groupBy(CounsellingOrder::getCounsellingInfoId).having(" num > 0 ");
|
// List<Map<String,Object>> mapList = this.counsellingOrderService.listMaps(orderQueryWrapper);
|
// Map<Long,Object> fristMap = new HashMap<>();
|
// if (CollectionUtil.isNotEmpty(mapList)){
|
//
|
// mapList.stream().forEach(stringObjectMap -> {
|
// fristMap.put(Long.parseLong(stringObjectMap.get("counsellingInfoId").toString()),stringObjectMap.get("num"));
|
// });
|
// }
|
// //查询标签总条数
|
// List<CounsellingTag> counsellingTags = this.counsellingTagService.list(new LambdaQueryWrapper<CounsellingTag>()
|
// .select(CounsellingTag::getId,CounsellingTag::getTagName));
|
// List<Long> custommerIds = page.getRecords().stream().map(CounsellingInfo::getUserId).collect(Collectors.toList());
|
// //查询客户ids
|
// List<Customer> customerList = this.customerService.list(new LambdaQueryWrapper<Customer>().select(Customer::getCustomerId,Customer::getNickName).in(Customer::getCustomerId,custommerIds));
|
// //查询套餐最低价
|
// List<Map<String,Object>> lowMapList = this.counsellingSetMealService.listMaps(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().in(CounsellingSetMeal::getCounsellingInfoId,counseIds)
|
// .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0));
|
//
|
// List<CounsellinginfoResponseDTO> counsellinginfoResponseDTOS = BeanUtil.copyToList(page.getRecords(),CounsellinginfoResponseDTO.class, CopyOptions.create());
|
// counsellinginfoResponseDTOS.stream().forEach(counsellinginfoResponseDTO -> {
|
// if (fristMap.get(counsellinginfoResponseDTO.getId()) != null){
|
// counsellinginfoResponseDTO.setIsFirstBuy(true);
|
// }
|
// if (StrUtil.isNotBlank(counsellinginfoResponseDTO.getCounsellingTagIds())){
|
// List<String> counsellingTagList = Arrays.asList(counsellinginfoResponseDTO.getCounsellingTagIds().split(","));
|
// String tagNames = counsellingTags.stream().filter(cou -> counsellingTagList.contains(cou.getId().toString())).map(CounsellingTag::getTagName).collect(Collectors.joining(","));
|
// //获取课程标签名称
|
//// LambdaQueryWrapper<CounsellingTag> counsellingTagLambdaQueryWrapper = new QueryWrapper<CounsellingTag>().select(" GROUP_CONCAT(tag_name) tagName ").lambda();
|
//// Map<String,Object> map = counsellingTagService.getMap(counsellingTagLambdaQueryWrapper.in(CounsellingTag::getId,counsellinginfoResponseDTO.getCounsellingTagIds().split(",")));
|
//// if (ObjectUtil.isNotEmpty(map)){
|
// counsellinginfoResponseDTO.setCounsellingTagNames(tagNames);
|
//// }
|
// }
|
// counsellinginfoResponseDTO.setPersonalProfile(null);
|
//
|
// counsellinginfoResponseDTO.setNikeName(customerList.stream().filter(cus -> counsellinginfoResponseDTO.getUserId().longValue() == cus.getCustomerId().longValue()).findFirst().get().getNickName());
|
//
|
//// BigDecimal lowPrice = this.counsellingSetMealService.getObj(new QueryWrapper<CounsellingSetMeal>().select(" counselling_info_id counsellingInfoId,IFNULL(min(price),0) price ").lambda().eq(CounsellingSetMeal::getCounsellingInfoId,counsellinginfoResponseDTO.getId())
|
//// .eq(CounsellingSetMeal::getSetMealType,1).eq(CounsellingSetMeal::getIsDelete,0),Convert::toBigDecimal);
|
//
|
//
|
// if (CollectionUtil.isNotEmpty(lowMapList)){
|
// lowMapList.stream().forEach(stringObjectMap -> {
|
// if (stringObjectMap.get("counsellingInfoId") != null){
|
// counsellinginfoResponseDTO.setLowPrice(new BigDecimal(stringObjectMap.get("price").toString()));
|
// }
|
// });
|
// if (counsellinginfoResponseDTO.getLowPrice() == null){
|
// counsellinginfoResponseDTO.setLowPrice(new BigDecimal(0));
|
// }
|
// }
|
//
|
//
|
// });
|
//
|
// return new SuccessResponseData<>(PageResultFactory.createPageResult(counsellinginfoResponseDTOS,page.getTotal(), Convert.toInt(page.getSize()),Convert.toInt(page.getCurrent())));
|
// }
|
//
|
// return new SuccessResponseData<>(PageResultFactory.createPageResult(new ArrayList<CounsellinginfoResponseDTO>(),page.getTotal(), Convert.toInt(page.getSize()),Convert.toInt(page.getCurrent())));
|
}
|
|
|
|
|
@ApiOperation("获取指定咨询师近多少天的特殊时间配置")
|
@GetResource (name = "获取指定咨询师近多少天的特殊时间配置", path = {"/counsellingInfo/getCounsellingSpecialTimeConfigByCounsellingInfoId","/worker/counsellingInfo/getCounsellingSpecialTimeConfigByCounsellingInfoId"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
|
@ApiImplicitParam(name = "dayNum", value = "最近多少天的特殊时间配置",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
|
})
|
public ResponseData<List<CounsellingSpecialTimeConfig>> getCounsellingSpecialTimeConfigByCounsellingInfoId(Long counsellingInfoId,Integer dayNum){
|
Date beginDate = new Date();
|
if (dayNum == null){
|
dayNum = 7;
|
}
|
Date endDate = DateUtil.offsetDay(beginDate,dayNum);
|
List<CounsellingSpecialTimeConfig> counsellingSpecialTimeConfigList = this.counsellingSpecialTimeConfigService.list(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>().ge(CounsellingSpecialTimeConfig::getSpecialDay,DateUtil.formatDate(beginDate))
|
.le(CounsellingSpecialTimeConfig::getSpecialDay,DateUtil.formatDate(endDate)).eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId));
|
return new SuccessResponseData<>(counsellingSpecialTimeConfigList);
|
}
|
|
|
@ApiOperation("获取指定咨询师近多少天的预约剩余人数")
|
@GetResource (name = "获取指定咨询师近多少天的预约剩余人数", path = {"/counsellingInfo/getReservationTimeTable","/worker/counsellingInfo/getReservationTimeTable"})
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
|
@ApiImplicitParam(name = "dayNum", value = "最近多少天的预约",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
|
})
|
public ResponseData<List<CounsellingReservationDTO>> getReservationTimeTable(Long counsellingInfoId, Integer dayNum){
|
if (dayNum == null){
|
dayNum =7 ;
|
}
|
Date nowDate = new Date();
|
Date beginTime = DateUtil.offsetHour(nowDate,2);
|
//当天时间date
|
String beginTimeStr = DateUtil.formatDate(beginTime);
|
int nowDay = DateUtil.dayOfWeekEnum(nowDate).getIso8601Value();
|
List<CounsellingReservationDTO> list = new ArrayList<>();
|
//获取最近几天的时间排表
|
List<DateTime> dateList = DateUtil.rangeToList(nowDate,DateUtil.offsetDay(new Date(),dayNum), DateField.DAY_OF_YEAR);
|
dateList.forEach(dateTime -> {
|
CounsellingReservationDTO counsellingReservationDTO = new CounsellingReservationDTO();
|
//查询是否有特殊时间点
|
long count = this.counsellingSpecialTimeConfigService.count(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>()
|
.eq(CounsellingSpecialTimeConfig::getSpecialDay,dateTime.toDateStr()).eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId)
|
.ne(CounsellingSpecialTimeConfig::getIsCancelDay,1));
|
//查询普通时间点
|
int day = DateUtil.dayOfWeekEnum(dateTime).getIso8601Value();
|
//查询是否取消当天
|
long cancleCount = this.counsellingSpecialTimeConfigService.count(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>()
|
.eq(CounsellingSpecialTimeConfig::getSpecialDay,dateTime.toDateStr()).eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId)
|
.eq(CounsellingSpecialTimeConfig::getIsCancelDay,1));
|
if (cancleCount > 0l){
|
counsellingReservationDTO.setRemainingNum(0l);
|
}else{
|
//查询预约记录
|
long reservCount = 0l;
|
// this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingInfoId)
|
// .ge(CounsellingOrderReservation::getReservationBeginTime,DateUtil.beginOfDay(dateTime)).le(CounsellingOrderReservation::getReservationEndTime,DateUtil.endOfDay(dateTime))
|
// .in(CounsellingOrderReservation::getStauts,1,2,3,4));
|
//查询普通时间点
|
List<CounsellingTimeConfig> timeConfigList = this.counsellingTimeConfigService.list(new LambdaQueryWrapper<CounsellingTimeConfig>().eq(CounsellingTimeConfig::getCounsellingInfoId,counsellingInfoId).eq(CounsellingTimeConfig::getWeekDay,day)
|
);
|
long dayCount = 0l;
|
if (CollectionUtil.isNotEmpty(timeConfigList)){
|
|
for (CounsellingTimeConfig counsellingTimeConfig:timeConfigList){
|
if (counsellingTimeConfig.getWeekDay().intValue() == nowDay && beginTimeStr.equals(dateTime.toDateStr())){
|
Date beginTimeDate = DateUtil.parseDateTime(DateUtil.formatDate(new Date())+" "+counsellingTimeConfig.getBeginTimePoint()+":00");
|
//判断时间是否
|
if (beginTimeDate.getTime() < beginTime.getTime() && beginTimeDate.getTime() >= nowDate.getTime()){
|
continue;
|
}
|
if (beginTimeDate.getTime() <= nowDate.getTime()){
|
continue;
|
}
|
}
|
|
dayCount++;
|
}
|
|
}
|
counsellingReservationDTO.setRemainingNum(dayCount +count-reservCount);
|
}
|
|
|
// //查询预约记录
|
// long reservCount = this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingInfoId)
|
// .ge(CounsellingOrderReservation::getReservationBeginTime,DateUtil.beginOfDay(dateTime)).le(CounsellingOrderReservation::getReservationEndTime,DateUtil.endOfDay(dateTime))
|
// .in(CounsellingOrderReservation::getStauts,1,2,3));
|
// if (count > 0){
|
// counsellingReservationDTO.setRemainingNum(count -reservCount);
|
// }else{
|
// //查询普通时间点
|
// long dayCount = this.counsellingTimeConfigService.count(new LambdaQueryWrapper<CounsellingTimeConfig>().eq(CounsellingTimeConfig::getCounsellingInfoId,counsellingInfoId).eq(CounsellingTimeConfig::getWeekDay,day));
|
// counsellingReservationDTO.setRemainingNum(dayCount -reservCount);
|
// }
|
counsellingReservationDTO.setCounsellingInfoId(counsellingInfoId);
|
counsellingReservationDTO.setReservationDay(dateTime);
|
list.add(counsellingReservationDTO);
|
});
|
return new SuccessResponseData<>(list);
|
}
|
|
|
|
/**
|
* 获取咨询订单预约记录列表(分页)
|
*/
|
@ApiOperation("查看日程(分页)")
|
@GetResource(name = "查看日程(分页)", path = "/counsellingInfo/pageCounsellingOrderReservation", requiredPermission = false)
|
public ResponseData<PageResult<CounsellingOrderReservation>> pageCounsellingOrderReservation(CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO) {
|
Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(), counsellingOrderReservationRequestDTO);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
@ApiOperation("获取指定咨询师近多少天的预约记录")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
|
@ApiImplicitParam(name = "dayNum", value = "最近多少天的预约",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
|
})
|
@GetResource(name = "获取指定咨询师近多少天的预约记录", path = {"/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoId","/worker/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoId"}, requiredPermission = false)
|
public ResponseData<List<CounsellingOrderReservationResponseDTO>> getCounsellingOrderReservationByCounsellingInfoId(Long counsellingInfoId,Integer dayNum) {
|
CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
|
counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
|
counsellingOrderReservationRequestDTO.setPageNo(1);
|
counsellingOrderReservationRequestDTO.setPageSize(Integer.MAX_VALUE);
|
counsellingOrderReservationRequestDTO.setSearchEndTime(DateUtil.endOfDay(new Date()).toString());
|
if(dayNum == null){
|
dayNum = 7;
|
}
|
counsellingOrderReservationRequestDTO.setSearchBeginTime(DateUtil.offsetDay(DateUtil.beginOfDay(new Date()),-dayNum).toString());
|
Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(counsellingOrderReservationRequestDTO), counsellingOrderReservationRequestDTO);
|
if (CollectionUtil.isNotEmpty(page.getRecords())){
|
return new SuccessResponseData<>(BeanUtil.copyToList(page.getRecords(),CounsellingOrderReservationResponseDTO.class));
|
}
|
return new SuccessResponseData<>();
|
}
|
|
|
@ApiOperation("获取指定咨询师当天之后多少天的预约记录")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
|
@ApiImplicitParam(name = "dayNum", value = "多少天后的预约",defaultValue = "7",dataTypeClass = Integer.class, paramType = "query")
|
})
|
@GetResource(name = "获取指定咨询师当天之后多少天的预约记录", path = {"/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoIdForAfterDay","/worker/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoIdForAfterDay"}, requiredPermission = false)
|
public ResponseData<List<CounsellingOrderReservationResponseDTO>> getCounsellingOrderReservationByCounsellingInfoIdForAfterDay(Long counsellingInfoId,Integer dayNum) {
|
CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
|
counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
|
counsellingOrderReservationRequestDTO.setPageNo(1);
|
counsellingOrderReservationRequestDTO.setPageSize(Integer.MAX_VALUE);
|
counsellingOrderReservationRequestDTO.setSearchBeginTime(DateUtil.beginOfDay(new Date()).toString());
|
if(dayNum == null){
|
dayNum = 7;
|
}
|
counsellingOrderReservationRequestDTO.setSearchEndTime(DateUtil.offsetDay(DateUtil.endOfDay(new Date()),dayNum).toString());
|
Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(counsellingOrderReservationRequestDTO), counsellingOrderReservationRequestDTO);
|
if (CollectionUtil.isNotEmpty(page.getRecords())){
|
return new SuccessResponseData<>(BeanUtil.copyToList(page.getRecords(),CounsellingOrderReservationResponseDTO.class));
|
}
|
return new SuccessResponseData<>();
|
}
|
|
@ApiOperation("获取指定咨询师星期时间点配置")
|
@GetResource(name = "获取指定咨询师星期时间点配置", path = {"/counsellingInfo/getCounsellingTimeConfigByCounsellingInfoId","/worker/counsellingInfo/getCounsellingTimeConfigByCounsellingInfoId"}, requiredPermission = false)
|
public ResponseData<List<CounsellingTimeConfig>> getCounsellingTimeConfigByCounsellingInfoId(Long counsellingInfoId){
|
List<CounsellingTimeConfig> counsellingTimeConfigs = this.counsellingTimeConfigService.list(new LambdaQueryWrapper<CounsellingTimeConfig>().eq(CounsellingTimeConfig::getCounsellingInfoId,counsellingInfoId));
|
return new SuccessResponseData<>(counsellingTimeConfigs);
|
|
}
|
|
|
@ApiOperation("添加合同签订")
|
@PostResource(name = "添加合同签订", path = "/contractRecord/add")
|
public ResponseData<?> add(@RequestBody ContractRecord contractRecord) {
|
contractRecord.setUserId(LoginContext.me().getLoginUser().getUserId());
|
//查询是否已存在合约,存在就更新
|
ContractRecord contractRecord1 = this.contractRecordService.getOne(new LambdaQueryWrapper<ContractRecord>().eq(ContractRecord::getUserId,LoginContext.me().getLoginUser().getUserId()));
|
if (contractRecord1 != null){
|
contractRecord1.setContractContent(contractRecord.getContractContent());
|
contractRecord1.setSignUrl(contractRecord.getSignUrl());
|
contractRecord1.setSigningTime(new Date());
|
this.contractRecordService.updateById(contractRecord1);
|
}else{
|
contractRecord.setSigningTime(new Date());
|
this.contractRecordService.save(contractRecord);
|
}
|
return new SuccessResponseData<>();
|
}
|
|
@ApiOperation("查询签订合同")
|
@GetResource(name = "查询签订合同", path = "/contractRecord/info")
|
public ResponseData<ContractRecord> info(Long userId) {
|
if (userId == null){
|
userId = LoginContext.me().getLoginUser().getUserId();
|
}
|
//查询是否已存在合约,存在就更新
|
ContractRecord contractRecord1 = this.contractRecordService.getOne(new LambdaQueryWrapper<ContractRecord>().eq(ContractRecord::getUserId,userId));
|
|
return new SuccessResponseData<ContractRecord>(contractRecord1);
|
}
|
|
@ApiOperation("创建咨询订单信息")
|
@PostResource(name = "创建咨询订单信息", path = "/counsellingOrder/createCounsellingOrder")
|
public ResponseData<CounsellingOrder> createCounsellingOrder(@RequestBody CreateCounsellingOrderRequest counsellingOrderRequest) {
|
counsellingOrderRequest.setIsBack(false);
|
counsellingOrderRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
|
CounsellingInfo counsellingInfo = this.counsellingInfoService.getOne(new LambdaQueryWrapper<CounsellingInfo>().select(CounsellingInfo::getId,CounsellingInfo::getListingStatus).eq(CounsellingInfo::getId,counsellingOrderRequest.getCounsellingInfoId()));
|
if (counsellingInfo != null){
|
if(counsellingInfo.getListingStatus().intValue() != 1){
|
return new ErrorResponseData<>("咨询师已经下架,无法进行购买,请联系咨询顾问");
|
}
|
}
|
Customer customer = this.customerService.getById(LoginContext.me().getLoginUser().getUserId());
|
if (customer.getStatusFlag() != null &&customer.getStatusFlag() !=1){
|
return new ErrorResponseData<>("账号已被冻结或者被注销,无法进行下单");
|
}
|
|
if (counsellingOrderRequest.getFirstAppointmentDate() != null && counsellingOrderRequest.getOrderType().intValue() ==1){
|
//验证未支付的首次咨询订单
|
long counselllingCount = this.counsellingOrderService.count(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getFirstAppointmentDate,DateUtil.formatDate(counsellingOrderRequest.getFirstAppointmentDate()))
|
.eq(CounsellingOrder::getFirstAppointmentTimes,counsellingOrderRequest.getFirstAppointmentTimes()).in(CounsellingOrder::getStatusFlag,0,1,2).eq(CounsellingOrder::getIsDelete,0).eq(CounsellingOrder::getCounsellingInfoId,counsellingOrderRequest.getCounsellingInfoId()));
|
if (counselllingCount >0){
|
throw new ServiceException("当前时间段已预约,请选择其他时间段!");
|
}
|
}
|
|
CounsellingOrder counsellingOrder = this.counsellingOrderService.createCounsellingOrder(counsellingOrderRequest);
|
return new SuccessResponseData<>(counsellingOrder);
|
}
|
|
|
|
@ApiOperation("咨询订单预约")
|
@PostResource(name = "咨询订单预约", path = "/counsellingOrderReservation/saveCounsellingOrderReservation")
|
public ResponseData<CounsellingOrderReservation> saveCounsellingOrderReservation(@RequestBody CounsellingReservationRequest counsellingReservationRequest) throws ParseException {
|
//查询咨询师当天是否取消预约
|
CounsellingSpecialTimeConfig specialTimeConfig = this.counsellingSpecialTimeConfigService.getOne(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>().eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
|
.eq(CounsellingSpecialTimeConfig::getSpecialDay,counsellingReservationRequest.getDayTime()).eq(CounsellingSpecialTimeConfig::getIsCancelDay,1));
|
if (specialTimeConfig != null){
|
throw new ServiceException("当天咨询已取消,无法进行预约,请群内联系咨询顾问!");
|
}
|
//判断是否有用户咨询师信息
|
CounsellingUser counsellingUserOld = this.counsellingUserService.getOne(new LambdaQueryWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
|
.eq(CounsellingUser::getUserId,LoginContext.me().getLoginUser().getUserId()));
|
if(counsellingUserOld.getIsFirstAppointment().intValue() != 1){
|
if (counsellingUserOld != null && counsellingUserOld.getResidueClassHours() != null && counsellingUserOld.getResidueClassHours().intValue() <= 0){
|
throw new ServiceException("预约失败,当前剩余课时不足,请群内联系咨询顾问!");
|
}
|
if (counsellingUserOld != null && counsellingUserOld.getResidueClassHours() != null && counsellingUserOld.getResidueClassHours().intValue() > 0){
|
int waitHour = this.counsellingOrderReservationService.getObj(new QueryWrapper<CounsellingOrderReservation>().select("IFNULL(sum(consume_course_hour),0) hour").lambda().eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
|
.eq(CounsellingOrderReservation::getUserId,LoginContext.me().getLoginUser().getUserId()).in(CounsellingOrderReservation::getStauts,1,2,3),Convert::toInt);
|
if (counsellingUserOld.getResidueClassHours().intValue() - waitHour <= 0){
|
throw new ServiceException("预约失败,当前剩余课时不足,请群内联系咨询顾问!");
|
}
|
|
}
|
}
|
|
|
CounsellingOrder counsellingOrder = null;
|
if (counsellingReservationRequest.getCounsellingOrderId() == null){
|
counsellingOrder = this.counsellingOrderService.getOne(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId())
|
.eq(CounsellingOrder::getUserId,LoginContext.me().getLoginUser().getUserId()).eq(CounsellingOrder::getStatusFlag,1).orderByDesc(CounsellingOrder::getCreateTime).last( " limit 1"));
|
}else{
|
counsellingOrder = this.counsellingOrderService.getById(counsellingReservationRequest.getCounsellingOrderId());
|
|
}
|
if (counsellingOrder == null){
|
throw new ServiceException("没有在咨询的订单,无法进行预约!");
|
}
|
|
//验证未支付的首次咨询订单
|
long counselllingCount = this.counsellingOrderService.count(new LambdaQueryWrapper<CounsellingOrder>().eq(CounsellingOrder::getFirstAppointmentDate,counsellingReservationRequest.getDayTime())
|
.eq(CounsellingOrder::getFirstAppointmentTimes,counsellingReservationRequest.getTimePoint()).in(CounsellingOrder::getStatusFlag,0,1,2).eq(CounsellingOrder::getIsDelete,0).eq(CounsellingOrder::getCounsellingInfoId,counsellingReservationRequest.getCounsellingId()));
|
if (counselllingCount >0){
|
throw new ServiceException("当前时间段已预约,请选择其他时间段!");
|
}
|
|
CounsellingOrderReservation counsellingOrderReservation = new CounsellingOrderReservation();
|
counsellingOrderReservation.setCounsellingOrderId(counsellingOrderReservation.getCounsellingOrderId());
|
counsellingOrderReservation.setCounsellingInfoId(counsellingOrder.getCounsellingInfoId());
|
counsellingOrderReservation.setCompanionUserId(counsellingOrder.getCompanionUserId());
|
counsellingOrderReservation.setConsultantUserId(counsellingOrder.getConsultantUserId());
|
counsellingOrderReservation.setCreateTime(new Date());
|
counsellingOrderReservation.setUserId(counsellingOrder.getUserId());
|
counsellingOrderReservation.setCounsellingOrderId(counsellingOrder.getId());
|
//跟进结束和开始预约时间设置耗时
|
if (StrUtil.isNotBlank(counsellingReservationRequest.getTimePoint()) && StrUtil.isNotBlank(counsellingReservationRequest.getDayTime())){
|
String beginTime = counsellingReservationRequest.getDayTime()+" "+counsellingReservationRequest.getTimePoint().split("-")[0]+":00";
|
counsellingOrderReservation.setReservationBeginTime(DateUtil.parseDateTime(beginTime));
|
String endTime = counsellingReservationRequest.getDayTime()+" "+counsellingReservationRequest.getTimePoint().split("-")[1]+":00";
|
counsellingOrderReservation.setReservationEndTime(DateUtil.parseDateTime(endTime));
|
counsellingOrderReservation.setConsumeCourseHour((int) Math.ceil((counsellingOrderReservation.getReservationEndTime().getTime() - counsellingOrderReservation.getReservationBeginTime().getTime())/3600000d));
|
|
if (counsellingUserOld != null && counsellingUserOld.getResidueClassHours() != null && counsellingUserOld.getResidueClassHours().intValue() > 0){
|
if (counsellingUserOld.getResidueClassHours().intValue() < counsellingOrderReservation.getConsumeCourseHour().intValue() ){
|
throw new ServiceException("预约失败,当前剩余课时不足,请群内联系咨询顾问!");
|
}
|
|
}
|
//验证是否重复预约
|
long count = this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getReservationBeginTime,counsellingOrderReservation.getReservationBeginTime())
|
.eq(CounsellingOrderReservation::getReservationEndTime,counsellingOrderReservation.getReservationEndTime()).eq(CounsellingOrderReservation::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId())
|
.eq(CounsellingOrderReservation::getUserId,counsellingOrderReservation.getUserId()).notIn(CounsellingOrderReservation::getStauts,5,6));
|
if (count >0){
|
return new ErrorResponseData<>("500","当前时间段已预约,请选择其他时间段!");
|
}
|
}
|
if (counsellingOrder.getOrderType().intValue() ==1){
|
counsellingOrderReservation.setStauts(2);
|
counsellingOrderReservation.setReservationType(1);
|
this.counsellingOrderReservationService.save(counsellingOrderReservation);
|
//更新订单的首次预约时间
|
counsellingOrder.setFirstAppointmentDate(DateUtil.parseDate(counsellingReservationRequest.getDayTime()));
|
counsellingOrder.setFirstAppointmentTimes(counsellingReservationRequest.getTimePoint());
|
counsellingUserOld.setFirstAppointmentDate(counsellingOrder.getFirstAppointmentDate());
|
counsellingUserOld.setFirstAppointmentTimes(counsellingOrder.getFirstAppointmentTimes());
|
if (counsellingReservationRequest.getCustomerUpdateRequest() != null){
|
counsellingOrder.setUserInfoJson(JSONUtil.toJsonStr(counsellingReservationRequest.getCustomerUpdateRequest()));
|
counsellingOrder.setPhone(counsellingReservationRequest.getCustomerUpdateRequest().getLinkPhone());
|
counsellingUserOld.setPhone(counsellingOrder.getPhone());
|
counsellingUserOld.setUserInfoJson(counsellingOrder.getUserInfoJson());
|
}
|
counsellingUserOld.setIsFirstAppointment(2);
|
this.counsellingOrderService.updateById(counsellingOrder);
|
this.counsellingUserService.updateById(counsellingUserOld);
|
|
|
|
CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
|
|
|
//将此条消息加入到可聊天的表中t_mental_appointment
|
MentalAppointment mentalAppointment = MentalAppointment.builder()
|
.userId(counsellingOrder.getUserId())
|
.type("1")
|
.statusFlag(1)
|
.appointmentDay(new SimpleDateFormat("yyyy-MM-dd").parse(counsellingReservationRequest.getDayTime()))
|
.beginTimePoint(counsellingReservationRequest.getTimePoint().split("-")[0])
|
.endTimePoint(counsellingReservationRequest.getTimePoint().split("-")[1])
|
.workerId(counsellingInfo.getUserId())
|
.build();
|
// 用户信息
|
CustomerInfo customerInfo = customerService.getCustomerInfoById(counsellingOrder.getUserId());
|
mentalAppointment.setUserName(customerInfo.getRealName());
|
mentalAppointment.setPhone(customerInfo.getLinkPhone());
|
mentalAppointmentService.save(mentalAppointment);
|
|
// 发送IM消息
|
ImPushDataDTO pushData1 = ImPushDataDTO.builder()
|
.type(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT.getCode())
|
.title(ImPushTypeEnum.C_TO_W_IM_1V1_START_CONSULT.getName())
|
.content("预约成功"+",请注意预约时间:"+counsellingReservationRequest.getDayTime()+counsellingReservationRequest.getTimePoint())
|
// .content("预约成功!")
|
.objId(ObjUtil.toString(counsellingInfo.getId()))
|
.data1(ObjUtil.toString(counsellingOrder.getUserId()))
|
.data2(ObjUtil.toString(counsellingInfo.getUserId()))
|
.build();
|
imBizService.messageSendPrivate(
|
ObjUtil.toString(counsellingOrder.getUserId()),
|
new String[]{ObjUtil.toString(counsellingInfo.getUserId())},
|
pushData1);
|
|
// 推送消息内容
|
String pushContent = "你的预约("+DateUtil.formatDate(counsellingOrder.getFirstAppointmentDate())+" "+counsellingOrder.getFirstAppointmentTimes()+")已确认,请按时参加";
|
// IM推送数据json
|
ImPushDataDTO pushData = ImPushDataDTO.builder()
|
.type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_PAY_SUCCESS.getCode())
|
.objId(ObjUtil.toString(counsellingOrderReservation.getId()))
|
.title("通知")
|
.data1(ObjUtil.toString(counsellingInfo.getUserId()))
|
.data2(ObjUtil.toString(counsellingOrder.getUserId()))
|
.content(pushContent)
|
// .extra("("+DateUtil.formatDate(counsellingOrder.getFirstAppointmentDate())+" "+counsellingOrder.getFirstAppointmentTimes()+")")
|
.build();
|
// 发送首次预约
|
imBizService.messageSendSystem(counsellingOrderReservation.getUserId()+"", new String[]{counsellingOrderReservation.getUserId()+""}, pushData, ImUserTypeEnum.USER, null, true);
|
|
|
//给咨询师发消息
|
Customer customerOld = this.customerService.getById(counsellingOrderReservation.getUserId());
|
|
String pushContent1 = "你有新的预约,请注意查收。预约用户:"+customerOld.getNickName()+",预约时间:"+DateUtil.formatDate(counsellingOrder.getFirstAppointmentDate())+" "+counsellingOrder.getFirstAppointmentTimes();
|
// +"预约时间:"+counsellingOrder.getEffectiveEndTime()+"~"+counsellingOrder.getEffectiveEndTime();
|
// IM推送数据json
|
ImPushDataDTO pushData2 = ImPushDataDTO.builder()
|
.type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_PAY_GROUP_SUCCESS.getCode())
|
.objId(ObjUtil.toString(counsellingInfo.getUserId()))
|
.title("通知")
|
.content(pushContent1)
|
.data1(ObjUtil.toString(counsellingOrder.getUserId()))
|
.data2(ObjUtil.toString(counsellingInfo.getUserId()))
|
// .extra("去查看。")
|
.build();
|
// 发送预约提示
|
imBizService.messageSendSystem(counsellingOrder.getUserId()+"", new String[]{counsellingInfo.getUserId()+""}, pushData2, ImUserTypeEnum.WORKER, PostIdEnum.PO_22, true);
|
}else{
|
counsellingOrderReservation.setStauts(1);
|
counsellingOrderReservation.setReservationType(2);
|
this.counsellingOrderReservationService.save(counsellingOrderReservation);
|
CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrder.getCounsellingInfoId());
|
|
// 推送消息内容
|
String pushContent = "你有新的预约申请等待审核,";
|
// IM推送数据json
|
ImPushDataDTO pushData = ImPushDataDTO.builder()
|
.type(ImPushTypeEnum.S_TO_W_TIP_CONSULT_AUDIT_APPOINTMENT_SUCCESS.getCode())
|
.objId(ObjUtil.toString(counsellingOrderReservation.getId()))
|
.title("通知")
|
.content(pushContent)
|
// .extra("去查看。")
|
.build();
|
// 发送预约提示
|
imBizService.messageSendSystem(counsellingOrderReservation.getUserId()+"", new String[]{counsellingInfo.getUserId()+""}, pushData, ImUserTypeEnum.WORKER, PostIdEnum.PO_22, true);
|
}
|
if (counsellingReservationRequest.getCustomerUpdateRequest() != null){
|
//更新用户信息
|
Customer customer = BeanUtil.toBean(counsellingReservationRequest.getCustomerUpdateRequest(), Customer.class);
|
customer.setCustomerId(LoginContext.me().getLoginUser().getUserId());
|
// 修改用户信息
|
customerService.updateCustomerRemoveCache(customer);
|
}
|
|
try {
|
|
CustomerUpdateRequest customerUpdateRequest = counsellingReservationRequest.getCustomerUpdateRequest();
|
Customer customer = new Customer();
|
BeanUtil.copyProperties(customerUpdateRequest,customer);
|
LoginUser loginUser = LoginContext.me().getLoginUser();
|
customer.setCustomerId(loginUser.getUserId());
|
customerService.updateById(customer);
|
}catch (Exception e){
|
e.printStackTrace();
|
log.info("编辑用户报错");
|
}
|
|
return new SuccessResponseData<>(counsellingOrderReservation);
|
}
|
|
|
@ApiOperation("根据咨询订单id查询咨询信息")
|
@GetResource(name = "根据咨询订单id查询咨询信息", path = {"/counsellingOrder/getCounsellingOrderInfoById","/worker/counsellingOrder/getCounsellingOrderInfoById"})
|
public ResponseData<CounsellingOrderResponseDTO> getCounsellingOrderInfoById(Long counsellingOrderId){
|
CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(counsellingOrderId);
|
CounsellingOrderResponseDTO counsellingOrderResponseDTO = BeanUtil.copyProperties(counsellingOrder,CounsellingOrderResponseDTO.class);
|
CounsellingInfo counsellingInfo = this.counsellingInfoService.getById(counsellingOrderResponseDTO.getCounsellingInfoId());
|
Customer customer = this.customerService.getById(counsellingInfo.getUserId());
|
counsellingOrderResponseDTO.setCounsellingName(customer.getNickName());
|
return new SuccessResponseData<>(counsellingOrderResponseDTO);
|
|
}
|
|
|
// @ApiOperation("分页查询指定条件的预约记录,指定咨询订单")
|
// @GetResource(name = "分页查询指定条件的预约记录,指定咨询订单", path = "/counsellingOrderReservation/getCounsellingOrderReservationForPage", requiredPermission = false)
|
// @ApiImplicitParams({
|
// @ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
|
// @ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
|
// @ApiImplicitParam(name = "counsellingOrderId", value = "咨询订单id", dataTypeClass = Integer.class, paramType = "query")
|
// } )
|
// public ResponseData<PageResult<CounsellingOrderReservation>> getCounsellingOrderReservationForPage(Integer pageNo, Integer pageSize,Long counsellingOrderId) {
|
// CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
|
// counsellingOrderReservationRequestDTO.setCounsellingOrderId(counsellingOrderId);
|
// Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findPage(PageFactory.defaultPage(), counsellingOrderReservationRequestDTO);
|
// return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
// }
|
|
@ApiOperation("分页查询指定条件的预约记录--指定咨询师")
|
@GetResource(name = "分页查询指定条件的预约记录--指定咨询师", path = "/counsellingOrderReservation/getCounsellingOrderReservationForPage", requiredPermission = false)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认10)", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "userId", value = "用户id,默认当前用户", dataTypeClass = Integer.class, paramType = "query")
|
} )
|
public ResponseData<PageResult<CounsellingOrderReservation>> getCounsellingOrderReservationForPage(Integer pageNo, Integer pageSize,Long counsellingInfoId,Long userId) {
|
CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
|
counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
|
if (userId != null){
|
counsellingOrderReservationRequestDTO.setCustomerId(userId);
|
}else{
|
counsellingOrderReservationRequestDTO.setCustomerId(LoginContext.me().getLoginUser().getUserId());
|
}
|
Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findReservationPage(PageFactory.defaultPage(), counsellingOrderReservationRequestDTO);
|
|
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
@ApiOperation("咨询预约-根据咨询师id和当前用户查询咨询课程详细信息")
|
@GetResource(name = "咨询预约-根据咨询师id和当前用户查询咨询课程详细信息", path = "/counsellingUser/getCounsellingUserInfo", requiredPermission = false)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Integer.class, paramType = "query"),
|
@ApiImplicitParam(name = "userId", value = "用户id,不传默认当前用户id", dataTypeClass = Integer.class, paramType = "query")
|
} )
|
public ResponseData<CounsellingUser> getCounsellingUserInfo(Long counsellingInfoId,Long userId) {
|
CounsellingUserRequest counsellingUserRequest = new CounsellingUserRequest();
|
counsellingUserRequest.setCounsellingInfoId(counsellingInfoId);
|
if (userId != null){
|
counsellingUserRequest.setUserId(userId);
|
|
}else{
|
counsellingUserRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
|
}
|
Page<CounsellingUser> page = this.counsellingUserService.findCounsellingUserPage(PageFactory.defaultPage(), counsellingUserRequest);
|
if (CollectionUtil.isNotEmpty(page.getRecords())){
|
return new SuccessResponseData<>(page.getRecords().get(0));
|
}
|
return new SuccessResponseData<>();
|
}
|
|
|
@Transactional
|
@ApiOperation("取消咨询预约")
|
@PostResource(name = "取消咨询预约", path = "/counsellingOrderReservation/cancleCounsellingReservation/{counsellingOrderReservationId}", requiredPermission = false)
|
public ResponseData<?> cancleCounsellingReservation(@PathVariable("counsellingOrderReservationId") Long counsellingOrderReservationId){
|
CounsellingOrderReservation counsellingOrderReservation = this.counsellingOrderReservationService.getById(counsellingOrderReservationId);
|
if (counsellingOrderReservation != null){
|
counsellingOrderReservation.setStauts(5);
|
}
|
CounsellingUser counsellingUser = this.counsellingUserService.getOne(new LambdaQueryWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId())
|
.eq(CounsellingUser::getUserId,counsellingOrderReservation.getUserId()).eq(CounsellingUser::getIsDelete,0)
|
.last(" limit 1 "));
|
//取消预约时间间隔,6小时
|
long minte = DateUtil.between(new Date(),counsellingOrderReservation.getReservationBeginTime(), DateUnit.MINUTE,false);
|
if (minte <= 360l && minte >=0){
|
|
// Customer customer = this.customerService.getById(counsellingOrderReservation.getUserId());
|
// customer.setCancelNum(customer.getCancelNum()+1);
|
// this.customerService.updateById(customer);
|
if (counsellingOrderReservation.getReservationType().intValue() != 1){
|
counsellingUser.setCancelNum(counsellingUser.getCancelNum()+1);
|
//每三次扣一次
|
if (counsellingUser.getCancelNum().intValue() > 0 && counsellingUser.getCancelNum().intValue()%3 == 0){
|
//分钟数
|
long minute = DateUtil.between(counsellingOrderReservation.getReservationBeginTime(),counsellingOrderReservation.getReservationEndTime(), DateUnit.MINUTE);
|
int ceil = (int) Math.ceil(minute / 60d);
|
CounsellingOrder counsellingOrderold = this.counsellingOrderService.getById(counsellingOrderReservation.getCounsellingOrderId());
|
|
//扣除工时
|
counsellingOrderold.setResidueClassHours(counsellingOrderold.getResidueClassHours().intValue() -1);
|
//判断是否完成咨询订单服务
|
if (counsellingOrderold.getResidueClassHours().intValue() <= 0 ){
|
counsellingOrderold.setStatusFlag(2);
|
counsellingUser.setStatusFlag(2);
|
}
|
this.counsellingOrderService.updateById(counsellingOrderold);
|
|
counsellingOrderReservation.setConsumeCourseHour(1);
|
counsellingOrderReservation.setRemark("多次提前取消预约,扣除课时");
|
|
counsellingUser.setResidueClassHours(counsellingUser.getResidueClassHours().intValue() - 1);
|
|
}
|
}
|
|
this.counsellingUserService.updateById(counsellingUser);
|
|
}
|
this.counsellingOrderReservationService.updateById(counsellingOrderReservation);
|
//首次咨询取消取消掉咨询订单内的首次咨询时间
|
if (counsellingOrderReservation.getReservationType().intValue() == 1){
|
this.counsellingOrderService.update(new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getFirstAppointmentDate,null).set(CounsellingOrder::getFirstAppointmentTimes,null)
|
.eq(CounsellingOrder::getId,counsellingOrderReservation.getCounsellingOrderId()));
|
//处理用户咨询预约
|
this.counsellingUserService.update(new LambdaUpdateWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingOrderReservation.getCounsellingInfoId())
|
.eq(CounsellingUser::getUserId,counsellingOrderReservation.getUserId()).set(CounsellingUser::getFirstAppointmentDate,null)
|
.set(CounsellingUser::getFirstAppointmentTimes,null).set(CounsellingUser::getIsFirstAppointment,1));
|
}
|
|
return new SuccessResponseData<>();
|
}
|
|
|
@ApiOperation("根据预约记录id获取咨询作业列表")
|
@GetResource(name = "根据预约记录id获取咨询作业列表", path ={"/counsellingReservationWork/list","/worker/counsellingReservationWork/list"} , requiredPermission = false)
|
public ResponseData<List<CounsellingReservationWork>> list(Long counsellingOrderReservationId) {
|
LambdaQueryWrapper<CounsellingReservationWork> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingReservationWork>().eq(CounsellingReservationWork::getIsDelete,false)
|
.orderByDesc(CounsellingReservationWork::getId).eq(CounsellingReservationWork::getCounsellingOrderReservationId,counsellingOrderReservationId);
|
return new SuccessResponseData<>(counsellingReservationWorkService.list(lambdaQueryWrapper));
|
}
|
|
@ApiOperation("获取咨询订单信息列表(分页)")
|
@GetResource(name = "获取咨询订单信息列表(分页)", path = "/counsellingOrder/page", requiredPermission = false)
|
public ResponseData<PageResult<CounsellingOrderResponseDTO>> counsellingOrderPage(CounsellingOrderRequest counsellingOrderRequest) {
|
counsellingOrderRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
|
Page<CounsellingOrderResponseDTO> page = this.counsellingOrderService.findCounsellingOrderPage(PageFactory.defaultPage(), counsellingOrderRequest);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
|
@ApiOperation("我的预约-咨询预约(分页)")
|
@GetResource(name = "我的预约-咨询预约(分页)", path = "/counsellingUser/page", requiredPermission = false)
|
public ResponseData<PageResult<CounsellingUser>> counsellingUserPage(CounsellingUserRequest counsellingUserRequest) {
|
counsellingUserRequest.setUserId(LoginContext.me().getLoginUser().getUserId());
|
Page<CounsellingUser> page = this.counsellingUserService.findCounsellingUserPage(PageFactory.defaultPage(), counsellingUserRequest);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
@ApiOperation("取消咨询订单")
|
@PostResource(name = "取消咨询订单", path = "/counsellingOrder/cancleCounsellingOrder")
|
public ResponseData<?> cancleCounsellingOrder(Long orderId) {
|
CounsellingOrder counsellingOrder = this.counsellingOrderService.getById(orderId);
|
if (counsellingOrder == null){
|
throw new ServiceException("订单不存在,请仔细检查!");
|
}
|
if (counsellingOrder.getStatusFlag().intValue() ==1 || counsellingOrder.getStatusFlag().intValue() == 2){
|
Date endDate = DateUtil.offsetHour(new Date(),24);
|
long countRes = this.counsellingOrderReservationService.count(new LambdaQueryWrapper<CounsellingOrderReservation>()
|
.eq(CounsellingOrderReservation::getCounsellingOrderId,orderId).ge(CounsellingOrderReservation::getReservationBeginTime,DateUtil.formatDateTime(new Date()))
|
.le(CounsellingOrderReservation::getReservationBeginTime,DateUtil.formatDateTime(endDate)).in(CounsellingOrderReservation::getStauts,1,2,3,4));
|
if (countRes > 0l){
|
throw new ServiceException("24小时有预约不能取消订单!");
|
}
|
}
|
|
|
LambdaUpdateWrapper<CounsellingOrder> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingOrder>().set(CounsellingOrder::getStatusFlag,9);
|
lambdaUpdateWrapper.eq(CounsellingOrder::getId, orderId);
|
this.counsellingOrderService.update(lambdaUpdateWrapper);
|
CounsellingOrder counsellingOrderTwo = this.counsellingOrderService.getById(orderId);
|
CounsellingUser counsellingUser = this.counsellingUserService.getOne(new LambdaQueryWrapper<CounsellingUser>().eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())
|
.eq(CounsellingUser::getUserId,counsellingOrder.getUserId()).eq(CounsellingUser::getIsDelete,0).last(" limit 1 "));
|
if (counsellingUser != null){
|
if (counsellingOrderTwo.getOrderType().intValue() ==1){
|
this.counsellingUserService.update(new LambdaUpdateWrapper<CounsellingUser>().set(CounsellingUser::getStatusFlag,9)
|
.set(CounsellingUser::getClassHours,0).set(CounsellingUser::getResidueClassHours,0).set(CounsellingUser::getIsFirstAppointment,null)
|
.set(CounsellingUser::getFirstAppointmentDate,null).set(CounsellingUser::getFirstAppointmentTimes,null)
|
.eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())
|
.eq(CounsellingUser::getUserId,counsellingOrder.getUserId()));
|
}else{
|
this.counsellingUserService.update(new LambdaUpdateWrapper<CounsellingUser>().set(CounsellingUser::getStatusFlag,9)
|
.set(CounsellingUser::getClassHours,0).set(CounsellingUser::getResidueClassHours,0)
|
.eq(CounsellingUser::getCounsellingInfoId,counsellingOrder.getCounsellingInfoId())
|
.eq(CounsellingUser::getUserId,counsellingOrder.getUserId()));
|
}
|
|
|
}
|
//取消对应的咨询预约
|
this.counsellingOrderReservationService.update(new LambdaUpdateWrapper<CounsellingOrderReservation>().eq(CounsellingOrderReservation::getCounsellingOrderId,orderId)
|
.in(CounsellingOrderReservation::getStauts,1,2,3).set(CounsellingOrderReservation::getStauts,5).set(CounsellingOrderReservation::getRemark,"订单退款取消"));
|
// //是否调用退款
|
if (StrUtil.isNotBlank(counsellingOrder.getTransactionNo())) {
|
if (counsellingOrder.getPayType().equals("1")) {
|
Map<String, Object> map = new HashMap(2);
|
map.put("transactionId", counsellingOrder.getOrderNo());
|
map.put("outTradeNo", counsellingOrder.getTransactionNo());
|
String result = HttpUtil.createGet(refundWxpayUrl).form(map).execute().body();
|
log.info("咨询订单微信退款信息:" + result);
|
} else if (counsellingOrder.getPayType().equals("2")) {
|
Map<String, Object> map = new HashMap(2);
|
map.put("outTradeNo", counsellingOrder.getOrderNo());
|
map.put("tradeNo", counsellingOrder.getTransactionNo());
|
String result = HttpUtil.createGet(refundAlipayUrl).form(map).execute().body();
|
log.info("咨询订单退款支付宝:{},{},{}", counsellingOrder.getOrderNo(), counsellingOrder.getTransactionNo(), result);
|
|
}
|
}
|
|
return new SuccessResponseData<>();
|
}
|
|
@ApiOperation("发送消息更新群最后聊天信息")
|
@PostResource(name = "发送消息更新群最后聊天信息", path = {"/group/{groupId}","/worker/group/{groupId}"}, requiredPermission = false)
|
public ResponseData<?> updateGroupIm(@PathVariable Long groupId){
|
this.imGroupService.update(new LambdaUpdateWrapper<ImGroup>().set(ImGroup::getLastChatTime,new Date()).eq(ImGroup::getId,groupId));
|
return new SuccessResponseData<>();
|
}
|
|
@ApiOperation("根据预约id查询预约记录详细")
|
@GetResource(name = "根据预约id查询预约记录详细", path ={"/counsellingInfo/getCounsellingOrderReservationResponseDTOById","/worker/counsellingInfo/getCounsellingOrderReservationResponseDTOById"}, requiredPermission = false)
|
public ResponseData<CounsellingOrderReservationResponseDTO> getCounsellingOrderReservationResponseDTOById(Long counsellingOrderReservationId){
|
CounsellingOrderReservation counsellingOrderReservation = this.counsellingOrderReservationService.getById(counsellingOrderReservationId);
|
CounsellingOrderReservationResponseDTO counsellingOrderReservationResponseDTO = BeanUtil.copyProperties(counsellingOrderReservation,CounsellingOrderReservationResponseDTO.class);
|
CounsellingOrder counsellingInfoOrder = this.counsellingOrderService.getById(counsellingOrderReservationResponseDTO.getCounsellingOrderId());
|
if (counsellingInfoOrder != null){
|
CounsellingOrderResponseDTO counsellingOrderResponseDTO = BeanUtil.copyProperties(counsellingInfoOrder,CounsellingOrderResponseDTO.class);
|
counsellingOrderReservationResponseDTO.setPhone(counsellingOrderResponseDTO.getPhone());
|
Customer customer = this.customerService.getById(counsellingInfoOrder.getUserId());
|
counsellingOrderReservationResponseDTO.setUserName(customer.getNickName());
|
}
|
return new SuccessResponseData<>(counsellingOrderReservationResponseDTO);
|
|
}
|
|
|
}
|