yanghb
2024-04-09 6682f1fc47b87124db517ba0b67ee86fcedff473
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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<List<MentalAppointmentPageDTO>> mentalAnalysisTimeConfigSchedule(Long counsellingInfoId, String searchBeginTime, String searchEndTime, String userNickName, String userTelephone, Integer statusFlag) {
        List<MentalAppointmentPageDTO> 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<PageResult<MentalAppointmentPageDTO>> mentalAnalysisTimeConfigSchedulePage(Integer pageNo, Integer pageSize, Long counsellingInfoId, String userNickName, String userTelephone, Integer statusFlag) {
        Page<MentalAppointmentPageDTO> 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<MentalAppointment> 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<Boolean> mentalAppointmentStartConsult(Long id) {
        boolean update = mentalAppointmentService.update(
                Wrappers.<MentalAppointment>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<Boolean> mentalAppointmentStopConsult(Long id) {
        boolean update = mentalAppointmentService.update(
                Wrappers.<MentalAppointment>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<Boolean> 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<Boolean> 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<List<MentalAppointment>> mentalAppointmentConsultOrderList(Long id, Long userId, Long workerId) {
        DateTime dateTime = DateUtil.date();
        String day = DateUtil.formatDate(dateTime);
        String time = DateUtil.format(dateTime, "HH:mm");
 
        List<MentalAppointment> list = mentalAppointmentService.list(
                Wrappers.<MentalAppointment>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);
    }
 
}