guohongjin
2024-05-01 1901fceb6ddaa56a57f3131191454554c3e77e68
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
package cn.stylefeng.guns.modular.business.controller;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.modular.business.dto.CounsellingOrderReservationRequestDTO;
import cn.stylefeng.guns.modular.business.dto.CounsellingOrderReservationResponseDTO;
import cn.stylefeng.guns.modular.business.entity.*;
import cn.stylefeng.guns.modular.business.service.*;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
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.annotation.BusinessLog;
import cn.stylefeng.roses.kernel.rule.enums.CustomerWorkStatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.PostIdEnum;
import cn.stylefeng.roses.kernel.rule.enums.PostTypeEnum;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
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 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 org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 咨询师信息管理类
 * @author guo
 */
@RestController
@Api(tags = "咨询师信息管理类")
@ApiResource(name = "咨询师信息管理类", resBizType = ResBizTypeEnum.BUSINESS)
@RequestMapping("/business")
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;
 
    /**
     * 添加咨询师信息
     */
    @ApiOperation("添加咨询师信息")
    @PostResource(name = "添加咨询师信息", path = "/counsellingInfo/add")
    @BusinessLog
    public ResponseData<?> add(@RequestBody CounsellingInfo counsellingInfo) {
        long count = this.counsellingInfoService.count(new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getUserId,counsellingInfo.getUserId())
                .eq(CounsellingInfo::getIsDelete,false));
        if (count > 0){
            return new ErrorResponseData<>("500","咨询师已存在,请勿重新添加!");
        }
        this.counsellingInfoService.saveOrUpdateCounsellingInfo(counsellingInfo);
        return new SuccessResponseData<>();
    }
 
    /**
     * 删除咨询师信息
     */
    @ApiOperation("删除咨询师信息")
    @PostResource(name = "删除咨询师信息", path = "/counsellingInfo/delete")
    @BusinessLog
    public ResponseData<?> delete(@RequestParam String ids) {
        if (StrUtil.isBlank(ids)){
            return new ErrorResponseData<>("500","id不能为空");
        }
        LambdaUpdateWrapper<CounsellingInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingInfo>().set(CounsellingInfo::getIsDelete,true);
        lambdaUpdateWrapper.in(CounsellingInfo::getId, ListUtil.toList(ids.split(",")));
        this.counsellingInfoService.update(lambdaUpdateWrapper);
        return new SuccessResponseData<>();
    }
 
    /**
     * 修改咨询师信息
     */
    @ApiOperation("修改咨询师信息")
    @PostResource(name = "修改咨询师信息", path = "/counsellingInfo/edit")
    @BusinessLog
    public ResponseData<?> edit(@RequestBody CounsellingInfo counsellingInfo) {
        long count = this.counsellingInfoService.count(new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getUserId,counsellingInfo.getUserId())
                .eq(CounsellingInfo::getIsDelete,false).ne(CounsellingInfo::getUserId,counsellingInfo.getUserId()));
        if (count > 0){
            return new ErrorResponseData<>("500","咨询师已存在,请勿重新添加!");
        }
        this.counsellingInfoService.saveOrUpdateCounsellingInfo(counsellingInfo);
        return new SuccessResponseData<>();
    }
 
    /**
     * 获取咨询师信息详情
     */
    @ApiOperation("获取咨询师信息详情")
    @GetResource(name = "获取咨询师信息详情", path = "/counsellingInfo/detail/{id}", requiredPermission = false)
    public ResponseData<CounsellingInfo> 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());
        }
 
        return new SuccessResponseData<>(counsellingInfo);
    }
 
    @ApiOperation("获取咨询师信息详情-根据用户id")
    @GetResource(name = "获取咨询师信息详情-根据用户id", path = "/counsellingInfo/detail/user/{userId}", requiredPermission = false)
    public ResponseData<CounsellingInfo> userDetail(@PathVariable("userId") Long userId) {
        CounsellingInfo counsellingInfo = this.counsellingInfoService.getOne(new LambdaQueryWrapper<CounsellingInfo>()
                .eq(CounsellingInfo::getUserId,userId).eq(CounsellingInfo::getIsDelete,0));
        if (counsellingInfo == null){
            return new SuccessResponseData<>(null);
        }
        //获取课程标签名称
        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());
        }
 
        return new SuccessResponseData<>(counsellingInfo);
    }
 
 
    /**
     * 获取咨询师信息列表
     *
     */
    @ApiOperation("获取咨询师信息列表")
    @GetResource(name = "获取咨询师信息列表", path = "/counsellingInfo/list", requiredPermission = false)
    public ResponseData<List<CounsellingInfo>> list(CounsellingInfo counsellingInfo) {
          LambdaQueryWrapper<CounsellingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getIsDelete,false)
                        .orderByDesc(CounsellingInfo::getId);
        lambdaQueryWrapper.eq(counsellingInfo.getListingStatus() != null,CounsellingInfo::getListingStatus,counsellingInfo.getListingStatus());
        List<Customer> customerList = this.customerService.getWorkerListByLineStatusAndPost(null, PostTypeEnum.CONSULT.getCode(), 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);
        }else{
            lambdaQueryWrapper.eq(CounsellingInfo::getUserId,-1);
        }
        List<CounsellingInfo> list = counsellingInfoService.list(lambdaQueryWrapper);
        if (CollectionUtil.isNotEmpty(list)){
            list.forEach(counsellingInfo1 -> {
                Customer customer = this.customerService.getById(counsellingInfo1.getUserId());
                if (customer != null){
                    counsellingInfo1.setUserName(customer.getNickName());
                }
            });
        }
        return new SuccessResponseData<>(list);
    }
 
    /**
     * 获取咨询师信息列表(分页)
     */
    @ApiOperation("获取咨询师信息列表(分页)")
    @GetResource(name = "获取咨询师信息列表(分页)", path = "/counsellingInfo/page", requiredPermission = false)
    public ResponseData<PageResult<CounsellingInfo>> page(CounsellingInfo counsellingInfo) {
        LambdaQueryWrapper<CounsellingInfo> lambdaQueryWrapper = new LambdaQueryWrapper<CounsellingInfo>().eq(CounsellingInfo::getIsDelete,false)
                    .orderByAsc(CounsellingInfo::getSort);
        lambdaQueryWrapper.eq(counsellingInfo.getListingStatus() != null,CounsellingInfo::getListingStatus,counsellingInfo.getListingStatus());
        if (StrUtil.isNotBlank(counsellingInfo.getUserName())){
           List<Long> customerIds = this.customerService.list(new LambdaQueryWrapper<Customer>().select(Customer::getCustomerId).like(Customer::getNickName,counsellingInfo.getUserName())
                    .eq(Customer::getStatusFlag,1).eq(Customer::getUserType,1)).stream().map(Customer::getCustomerId).collect(Collectors.toList());
           if (CollectionUtil.isNotEmpty(customerIds)){
               lambdaQueryWrapper.in(CounsellingInfo::getUserId,customerIds);
           }else{
               lambdaQueryWrapper.eq(CounsellingInfo::getUserId,-1);
           }
 
        }
 
        Page<CounsellingInfo> page = this.counsellingInfoService.page(PageFactory.defaultPage(), lambdaQueryWrapper);
        if (CollectionUtil.isNotEmpty(page.getRecords())){
            page.getRecords().forEach(counsellingInfo1 -> {
                Customer customer = this.customerService.getById(counsellingInfo1.getUserId());
                if (customer != null){
                    counsellingInfo1.setUserName(customer.getNickName());
                }
            });
        }
        return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
    }
 
    @ApiOperation("修改咨询师上架状态")
    @PostResource(name = "修改咨询师上架状态", path = "/counsellingInfo/updateStatus")
    @BusinessLog
    public ResponseData<?> updateStatus(String ids, Integer status) {
        if (StrUtil.isBlank(ids)){
            return new ErrorResponseData<>("500","id不能为空");
        }
        LambdaUpdateWrapper<CounsellingInfo> lambdaUpdateWrapper = new LambdaUpdateWrapper<CounsellingInfo>();
        lambdaUpdateWrapper.in(CounsellingInfo::getId, ListUtil.toList(ids.split(",")));
        lambdaUpdateWrapper.set(CounsellingInfo::getListingStatus,status)
                .set(CounsellingInfo::getUpdateUser, LoginContext.me().getLoginUser().getUserId());
        this.counsellingInfoService.update(lambdaUpdateWrapper);
        return new SuccessResponseData<>();
    }
 
    @ApiOperation("咨询预约特殊时间配置")
    @PostResource(name = "咨询预约特殊时间配置", path = "/counsellingInfo/saveOrUpdateSpecialTimeConfig")
    @BusinessLog
    public ResponseData<?> saveOrUpdateSpecialTimeConfig(@RequestBody List<CounsellingSpecialTimeConfig> counsellingSpecialTimeConfigs){
 
        if (CollectionUtil.isNotEmpty(counsellingSpecialTimeConfigs)){
            this.counsellingSpecialTimeConfigService.remove(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>().eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingSpecialTimeConfigs.get(0).getCounsellingInfoId())
                    .eq(CounsellingSpecialTimeConfig::getSpecialDay,DateUtil.formatDate(counsellingSpecialTimeConfigs.get(0).getSpecialDay())));
            if (counsellingSpecialTimeConfigs.get(0).getIsCancelDay().intValue() ==1){
                CounsellingSpecialTimeConfig counsellingSpecialTimeConfig = counsellingSpecialTimeConfigs.get(0);
 
                counsellingSpecialTimeConfig.setSpecialBeginTimePoint(null);
                counsellingSpecialTimeConfig.setSpecialEndTimePoint(null);
                this.counsellingSpecialTimeConfigService.save(counsellingSpecialTimeConfig);
                return new SuccessResponseData<>();
 
            }
            this.counsellingSpecialTimeConfigService.saveOrUpdateBatch(counsellingSpecialTimeConfigs);
        }
 
        return new SuccessResponseData<>();
    }
 
 
    @ApiOperation("置空咨询预约特殊时间配置")
    @PostResource(name = "置空咨询预约特殊时间配置", path = "/counsellingInfo/restSpecialTimeConfig")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "counsellingInfoId", value = "咨询师id", dataTypeClass = Long.class, paramType = "query"),
            @ApiImplicitParam(name = "specialDay", value = "日期 yyyy-MM-dd)", dataTypeClass = String.class, paramType = "query")
    })
    @BusinessLog
    public ResponseData<?> restSpecialTimeConfig(Long counsellingInfoId,String specialDay){
        this.counsellingSpecialTimeConfigService.remove(new LambdaQueryWrapper<CounsellingSpecialTimeConfig>()
                .eq(CounsellingSpecialTimeConfig::getCounsellingInfoId,counsellingInfoId).eq(CounsellingSpecialTimeConfig::getSpecialDay,specialDay));
        return new SuccessResponseData<>();
    }
 
    @ApiOperation("获取指定咨询师近30天的特殊时间配置")
    @GetResource (name = "获取指定咨询师近30天的特殊时间配置", path = "/counsellingInfo/getCounsellingSpecialTimeConfigByCounsellingInfoId")
    @BusinessLog
    public ResponseData<List<CounsellingSpecialTimeConfig>> getCounsellingSpecialTimeConfigByCounsellingInfoId(Long counsellingInfoId){
        Date beginDate = new Date();
        Date endDate = DateUtil.offsetDay(beginDate,30);
        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/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("获取指定咨询师近30天的预约记录")
    @GetResource(name = "获取指定咨询师近30天的预约记录", path = "/counsellingInfo/getCounsellingOrderReservationByCounsellingInfoId", requiredPermission = false)
    public ResponseData<List<CounsellingOrderReservationResponseDTO>> getCounsellingOrderReservationByCounsellingInfoId(Long counsellingInfoId) {
        CounsellingOrderReservationRequestDTO counsellingOrderReservationRequestDTO = new CounsellingOrderReservationRequestDTO();
        counsellingOrderReservationRequestDTO.setCounsellingInfoId(counsellingInfoId);
        counsellingOrderReservationRequestDTO.setPageNo(1);
        counsellingOrderReservationRequestDTO.setPageSize(Integer.MAX_VALUE);
        counsellingOrderReservationRequestDTO.setSearchEndTime(DateUtil.formatDateTime(new Date()));
        counsellingOrderReservationRequestDTO.setSearchBeginTime(DateUtil.offsetDay(new Date(),-30).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", 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);
        
    }
    
}