package cn.stylefeng.rest.modular.worker.controller; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjUtil; import cn.stylefeng.guns.modular.business.dto.ImPushDataDTO; import cn.stylefeng.guns.modular.business.dto.MentalAppointmentPageDTO; import cn.stylefeng.guns.modular.business.dto.request.MentalAppointmentAssignWorkRequest; import cn.stylefeng.guns.modular.business.dto.request.MentalAppointmentRecordRequest; import cn.stylefeng.guns.modular.business.entity.MentalAppointment; import cn.stylefeng.guns.modular.business.service.IMentalAppointmentService; import cn.stylefeng.guns.modular.business.service.impl.ImBizService; 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.ImPushTypeEnum; import cn.stylefeng.roses.kernel.rule.enums.MentalAppointmentConsultStatusEnum; import cn.stylefeng.roses.kernel.rule.enums.MentalAppointmentStatusEnum; 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 com.baomidou.mybatisplus.core.toolkit.Wrappers; 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 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.util.Arrays; import java.util.List; @RestController @Api(tags = "工作人员") @ApiResource(name = "工作人员") @RequestMapping("/worker") public class MentalAnalysisTimeConfigController { @Resource private ImBizService imBizService; @Resource private IMentalAppointmentService mentalAppointmentService; @ApiOperation("性格分析师-查看行程") @GetResource(name = "性格分析师-查看行程", path = "/mentalAnalysisTimeConfigSchedule", requiredPermission = false) @ApiImplicitParams({ @ApiImplicitParam(name = "counsellingInfoId", value = "性格分析师ID", dataTypeClass = Long.class, paramType = "query"), @ApiImplicitParam(name = "searchBeginTime", value = "开始时间", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "searchEndTime", value = "结束时间", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "userNickName", value = "用户姓名", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "userTelephone", value = "联系电话", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "statusFlag", value = "状态:1已分配,2服务中,3已完成,9已取消", dataTypeClass = Integer.class, paramType = "query"), }) public ResponseData> mentalAnalysisTimeConfigSchedule(Long counsellingInfoId, String searchBeginTime, String searchEndTime, String userNickName, String userTelephone, Integer statusFlag) { List list = mentalAppointmentService.mentalAnalysisTimeConfigSchedule(searchBeginTime, searchEndTime, counsellingInfoId, null, userNickName, userTelephone, statusFlag, null); return new SuccessResponseData<>(list); } @ApiOperation("性格分析师-查看行程(分页)") @GetResource(name = "性格分析师-查看行程(分页)", path = "/mentalAnalysisTimeConfigSchedulePage", requiredPermission = false) @ApiImplicitParams({ @ApiImplicitParam(name = "pageNo", value = "分页:第几页(从1开始)", dataTypeClass = Integer.class, paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "分页:每页大小(默认20)", dataTypeClass = Integer.class, paramType = "query"), @ApiImplicitParam(name = "counsellingInfoId", value = "性格分析师ID", dataTypeClass = Long.class, paramType = "query"), @ApiImplicitParam(name = "userNickName", value = "用户姓名", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "userTelephone", value = "联系电话", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "statusFlag", value = "状态:1预约中,2服务中,3已完成,9已取消", dataTypeClass = Integer.class, paramType = "query"), }) public ResponseData> mentalAnalysisTimeConfigSchedulePage(Integer pageNo, Integer pageSize, Long counsellingInfoId, String userNickName, String userTelephone, Integer statusFlag) { Page page = mentalAppointmentService.getPage( PageFactory.page(pageNo, pageSize), counsellingInfoId, null, userNickName, userTelephone, statusFlag, Arrays.asList(MentalAppointmentStatusEnum.WAIT_SERVICE.getCode(), MentalAppointmentStatusEnum.IN_SERVICE.getCode(), MentalAppointmentStatusEnum.DONE.getCode()) ); return new SuccessResponseData<>(PageResultFactory.createPageResult(page)); } @ApiOperation("性格分析师-预约详情") @GetResource(name = "性格分析师-预约详情", path = "/mentalAppointmentDetail", requiredPermission = false) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "预约ID", dataTypeClass = Long.class, paramType = "query"), }) public ResponseData mentalAppointmentDetail(Long id) { MentalAppointment appointment = mentalAppointmentService.getById(id); return new SuccessResponseData<>(appointment); } @ApiOperation("性格分析师-开始咨询") @GetResource(name = "性格分析师-开始咨询", path = "/mentalAppointmentStartConsult", requiredPermission = false) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "预约ID", dataTypeClass = Long.class, paramType = "query"), }) public ResponseData mentalAppointmentStartConsult(Long id) { boolean update = mentalAppointmentService.update( Wrappers.lambdaUpdate() .set(MentalAppointment::getStatusFlag, MentalAppointmentStatusEnum.IN_SERVICE.getCode()) .set(MentalAppointment::getConsultStatus, MentalAppointmentConsultStatusEnum.IN_CONSULT.getCode()) .eq(MentalAppointment::getId, id) ); return new SuccessResponseData<>(update); } @ApiOperation("性格分析师-结束咨询") @GetResource(name = "性格分析师-结束咨询", path = "/mentalAppointmentStopConsult", requiredPermission = false) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "预约ID", dataTypeClass = Long.class, paramType = "query"), }) public ResponseData mentalAppointmentStopConsult(Long id) { boolean update = mentalAppointmentService.update( Wrappers.lambdaUpdate() .set(MentalAppointment::getStatusFlag, MentalAppointmentStatusEnum.DONE.getCode()) .set(MentalAppointment::getConsultStatus, MentalAppointmentConsultStatusEnum.DONE.getCode()) .eq(MentalAppointment::getId, id) ); try { MentalAppointment o = mentalAppointmentService.getById(id); // 推送消息内容 String pushContent = "1v1咨询结束"; // IM推送数据json ImPushDataDTO pushData_u = ImPushDataDTO.builder() .type(ImPushTypeEnum.C_TO_C_TIP_STOP_IM.getCode()) .objId(ObjUtil.toString(o.getId())) .title("通知") .content(pushContent) .data1(ObjUtil.toString(o.getWorkerId())) .data2(ObjUtil.toString(o.getUserId())) .build(); // 通知性格分析师 imBizService.messageSendSystem(o.getWorkerId()+"", new String[]{o.getUserId()+""}, pushData_u, null, null, false); } catch (Exception e) { e.printStackTrace(); } return new SuccessResponseData<>(update); } @ApiOperation("性格分析师-布置作业") @PostResource(name = "性格分析师-布置作业", path = "/mentalAppointmentAssignWorkRequest", requiredPermission = false) public ResponseData mentalAppointmentAssignWorkRequest(@RequestBody MentalAppointmentAssignWorkRequest req) { MentalAppointment mentalAppointment = BeanUtil.toBean(req, MentalAppointment.class); boolean update = mentalAppointmentService.updateById(mentalAppointment); return new SuccessResponseData<>(update); } @ApiOperation("性格分析师-咨询记录内容") @PostResource(name = "性格分析师-咨询记录内容", path = "/mentalAppointmentAddRecordRequest", requiredPermission = false) public ResponseData mentalAppointmentAddRecordRequest(@RequestBody MentalAppointmentRecordRequest req) { MentalAppointment mentalAppointment = BeanUtil.toBean(req, MentalAppointment.class); boolean update = mentalAppointmentService.updateById(mentalAppointment); return new SuccessResponseData<>(update); } @ApiOperation("性格分析师-当前可咨询订单") @GetResource(name = "性格分析师-当前可咨询订单", path = "/mentalAppointmentConsultOrderList", requiredPermission = false) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "预约ID", dataTypeClass = Long.class, paramType = "query"), @ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = Long.class, paramType = "query"), @ApiImplicitParam(name = "workerId", value = "性格分析师ID", dataTypeClass = Long.class, paramType = "query"), }) public ResponseData> mentalAppointmentConsultOrderList(Long id, Long userId, Long workerId) { DateTime dateTime = DateUtil.date(); String day = DateUtil.formatDate(dateTime); String time = DateUtil.format(dateTime, "HH:mm"); List list = mentalAppointmentService.list( Wrappers.lambdaUpdate() .in(MentalAppointment::getStatusFlag, Arrays.asList( MentalAppointmentStatusEnum.WAIT_SERVICE.getCode(), MentalAppointmentStatusEnum.IN_SERVICE.getCode() )) .eq(MentalAppointment::getAppointmentDay, day) .le(MentalAppointment::getBeginTimePoint, time) .ge(MentalAppointment::getEndTimePoint, time) .eq(userId != null, MentalAppointment::getUserId, userId) .eq(workerId != null, MentalAppointment::getWorkerId, workerId) .eq(id != null, MentalAppointment::getId, id) .orderByDesc(MentalAppointment::getStatusFlag) ); return new SuccessResponseData<>(list); } }