package cn.stylefeng.guns.modular.business.controller;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.util.StrUtil;
|
import cn.stylefeng.guns.modular.business.dto.BaseIdNameDTO;
|
import cn.stylefeng.guns.modular.business.dto.CounsellingOrderReservationResponseDTO;
|
import cn.stylefeng.guns.modular.business.dto.UserCounsellingTotalDTO;
|
import cn.stylefeng.guns.modular.business.dto.UserMentalAppointmentPageResponseDTO;
|
import cn.stylefeng.guns.modular.business.dto.request.UserCounsellingOrderReservationRequestDTO;
|
import cn.stylefeng.guns.modular.business.entity.*;
|
import cn.stylefeng.guns.modular.business.service.*;
|
import cn.stylefeng.roses.kernel.customer.api.pojo.UserDetailMentalTestRecordDTO;
|
import cn.stylefeng.roses.kernel.customer.api.pojo.UserDetailMentalTestRecordNlwpDTO;
|
import cn.stylefeng.roses.kernel.customer.api.pojo.UserManagePageResponseDTO;
|
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.CustomerUserTypeEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
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.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.google.common.collect.Lists;
|
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.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@RestController
|
@Api(tags = "用户管理")
|
@ApiResource(name = "用户管理", resBizType = ResBizTypeEnum.BUSINESS)
|
@RequestMapping("/userManage")
|
public class UserManageController {
|
|
@Resource
|
private IAreaService areaService;
|
|
@Resource
|
private CustomerService customerService;
|
|
@Resource
|
private IMentalTestRecordService mentalTestRecordService;
|
|
@Resource
|
private IMentalTestQuestionService mentalTestQuestionService;
|
|
@Resource
|
private IMentalTestOptionService mentalTestOptionService;
|
|
@Resource
|
private IMentalTestResultService mentalTestResultService;
|
|
@Resource
|
private IMentalTestResultSetService mentalTestResultSetService;
|
|
@Resource
|
private IMentalAppointmentService mentalAppointmentService;
|
|
@Resource
|
private ICounsellingOrderReservationService counsellingOrderReservationService;
|
|
@Resource
|
private ICounsellingOrderService counsellingOrderService;
|
|
@Resource
|
private IImGroupService imGroupService;
|
|
@ApiOperation("用户信息(分页)")
|
@GetResource(name = "用户信息(分页)", path = "/page")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageNo", value = "当前页数", dataTypeClass = Integer.class, defaultValue = "1"),
|
@ApiImplicitParam(name = "pageSize", value = "分页条数", dataTypeClass = Integer.class, defaultValue = "20"),
|
@ApiImplicitParam(name = "name", value = "名称", dataTypeClass = String.class),
|
@ApiImplicitParam(name = "telephone", value = "联系电话", dataTypeClass = String.class),
|
@ApiImplicitParam(name = "statusFlag", value = "用户状态:1-启用,2-禁用", dataTypeClass = Integer.class),
|
})
|
public ResponseData<PageResult<UserManagePageResponseDTO>> page(Integer pageNo, Integer pageSize, String name, String telephone, Integer statusFlag) {
|
Page<UserManagePageResponseDTO> page = customerService.getCustomerPage(
|
PageFactory.page(pageNo, pageSize),
|
CustomerUserTypeEnum.USER.getCode(),
|
null,
|
name,
|
telephone,
|
statusFlag
|
);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
@ApiOperation("获取详情")
|
@GetResource(name = "获取详情", path = "/detail/{id}")
|
public ResponseData<UserManagePageResponseDTO> detail(@PathVariable("id") Long id) {
|
// 查询用户详情
|
Page<UserManagePageResponseDTO> page = customerService.getCustomerPage(
|
PageFactory.page(1, 1),
|
CustomerUserTypeEnum.USER.getCode(),
|
id,
|
null, null, null
|
);
|
|
// 用户信息
|
UserManagePageResponseDTO dto = page.getRecords().stream().findFirst().orElseThrow(() -> new RuntimeException("用户不存在"));
|
|
// 心理测试记录(最新1条)
|
MentalTestRecord mentalTestRecord = mentalTestRecordService.getOne(
|
Wrappers.<MentalTestRecord>lambdaQuery()
|
.eq(MentalTestRecord::getUserId, dto.getCustomerId())
|
.eq(MentalTestRecord::getResultCalculateMode, 2)
|
.orderByDesc(MentalTestRecord::getCreateTime)
|
.last("limit 1")
|
);
|
dto.setMentalTestRecord(BeanUtil.toBean(mentalTestRecord, UserDetailMentalTestRecordDTO.class));
|
|
if (StrUtil.isNotBlank(dto.getCityCode())) {
|
dto.setCityCodeStr(areaService.getNameByCodeAddPrefix("/", dto.getCityCode()));
|
}
|
|
return new SuccessResponseData<>(dto);
|
}
|
|
@ApiOperation(value = "查询NlWP", notes = "使用心理测试记录ID进行查询")
|
@GetResource(name = "查询NlWP", path = "/mentalTestRecord")
|
public ResponseData<UserDetailMentalTestRecordNlwpDTO> mentalTestRecord(Long id) {
|
// 用户详情心理测试记录NLWP
|
UserDetailMentalTestRecordNlwpDTO dto = new UserDetailMentalTestRecordNlwpDTO();
|
|
// 答题记录
|
MentalTestRecord mentalTestRecord = mentalTestRecordService.getById(id);
|
dto.setContent(mentalTestRecord.getContent());
|
|
// 封装选项列表
|
dto.setItemList(
|
mentalTestResultSetService.list(
|
Wrappers.<MentalTestResultSet>lambdaQuery()
|
.eq(MentalTestResultSet::getTopicId, mentalTestRecord.getTopicId())
|
.eq(MentalTestResultSet::getResultCalculateMode, mentalTestRecord.getResultCalculateMode())
|
).stream()
|
.map(o -> BeanUtil.toBean(o, UserDetailMentalTestRecordNlwpDTO.ItemDTO.class))
|
.collect(Collectors.toList())
|
);
|
|
// 查询所有问题、选择
|
List<MentalTestQuestion> questionAll = mentalTestQuestionService.list(
|
Wrappers.<MentalTestQuestion>lambdaQuery()
|
.select(MentalTestQuestion::getId, MentalTestQuestion::getTitle)
|
.eq(MentalTestQuestion::getTopicId, mentalTestRecord.getTopicId())
|
);
|
List<MentalTestOption> optionAll = mentalTestOptionService.list(
|
Wrappers.<MentalTestOption>lambdaQuery().eq(MentalTestOption::getTopicId, mentalTestRecord.getTopicId())
|
);
|
|
|
// 所有答题
|
List<MentalTestResult> answerAll = mentalTestResultService.list(
|
Wrappers.<MentalTestResult>lambdaQuery().eq(MentalTestResult::getAnswerNo, mentalTestRecord.getAnswerNo())
|
);
|
|
List<Long> questionIds = answerAll.stream().map(MentalTestResult::getQuestionId).distinct().collect(Collectors.toList());
|
|
// 封装问题答案列表
|
dto.setQaList(
|
questionIds.stream().map(qid -> {
|
UserDetailMentalTestRecordNlwpDTO.QaDTO qaDTO = new UserDetailMentalTestRecordNlwpDTO.QaDTO();
|
|
qaDTO.setTitle(questionAll.stream()
|
.filter(q -> q.getId().equals(qid))
|
.findFirst().map(MentalTestQuestion::getTitle).orElse("")
|
);
|
|
qaDTO.setOptionList(answerAll.stream()
|
.filter(as -> as.getQuestionId().equals(qid))
|
.map(as -> {
|
UserDetailMentalTestRecordNlwpDTO.QaDTO.OptionDto optionDto = new UserDetailMentalTestRecordNlwpDTO.QaDTO.OptionDto();
|
|
MentalTestOption option = optionAll.stream()
|
.filter(op -> as.getQuestionId().equals(qid) && as.getItemNo().equals(op.getItemNo()))
|
.findFirst()
|
.orElse(new MentalTestOption());
|
|
optionDto.setItemNo(option.getItemNo());
|
optionDto.setContent(option.getContent());
|
|
return optionDto;
|
})
|
.collect(Collectors.toList())
|
);
|
return qaDTO;
|
}).collect(Collectors.toList())
|
);
|
return new SuccessResponseData<>(dto);
|
}
|
|
@ApiOperation("修改状态")
|
@PostResource(name = "修改状态", path = "/updateStatus")
|
@BusinessLog
|
public ResponseData<?> updateStatus(String ids, Integer status) {
|
if (StrUtil.isBlank(ids)){
|
return new ErrorResponseData<>("500","id不能为空");
|
}
|
for (String id : ids.split(",")) {
|
Customer o = new Customer();
|
o.setCustomerId(Long.valueOf(id));
|
o.setStatusFlag(status);
|
customerService.updateCustomerRemoveCache(o);
|
}
|
return new SuccessResponseData<>();
|
}
|
|
@BusinessLog
|
@ApiOperation("修改销售")
|
@PostResource(name = "修改销售", path = "/updateClassConsultWorkerId")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id", value = "用户id", dataTypeClass = Long.class),
|
@ApiImplicitParam(name = "classWorkerId", value = "幸福顾问(课程销售)", dataTypeClass = Long.class),
|
@ApiImplicitParam(name = "consultWorkerId", value = "咨询顾问(咨询销售)", dataTypeClass = Long.class),
|
})
|
public ResponseData<?> updateClassConsultWorkerId(Long id, Long classWorkerId, Long consultWorkerId) {
|
if (id == null){
|
return new ErrorResponseData<>("500","id不能为空");
|
}
|
|
Customer o = new Customer();
|
o.setCustomerId(Long.valueOf(id));
|
if (classWorkerId != null) {
|
o.setClassWorkerId(classWorkerId);
|
//更新指定业务的顾问信息
|
imGroupService.updateGroupUserForOrderinfo(classWorkerId,1,id);
|
}
|
if (consultWorkerId != null) {
|
o.setConsultWorkerId(consultWorkerId);
|
imGroupService.updateGroupUserForOrderinfo(consultWorkerId,2,id);
|
}
|
boolean update = customerService.updateCustomerRemoveCache(o);
|
|
|
return new SuccessResponseData<>(update);
|
}
|
|
@ApiOperation("用户(选择)列表")
|
@GetResource(name = "用户(选择)列表", path = "/userSelectList")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "showId", value = "用户ID", dataTypeClass = String.class),
|
@ApiImplicitParam(name = "nickName", value = "用户昵称", dataTypeClass = String.class),
|
})
|
public ResponseData<List<BaseIdNameDTO>> userSelectList(String showId, String nickName) {
|
List<BaseIdNameDTO> list = customerService.list(
|
Wrappers.<Customer>lambdaQuery()
|
.eq(Customer::getStatusFlag, StatusEnum.ENABLE.getCode())
|
.eq(Customer::getUserType, CustomerUserTypeEnum.USER.getCode())
|
.like(StrUtil.isNotBlank(showId), Customer::getShowId, showId)
|
.like(StrUtil.isNotBlank(nickName), Customer::getNickName, nickName)
|
).stream().map(
|
o -> BaseIdNameDTO.builder()
|
.id(o.getCustomerId())
|
.name(o.getNickName())
|
.build()
|
).collect(Collectors.toList());
|
|
return new SuccessResponseData(list);
|
}
|
|
@ApiOperation("性格分析1v1咨询预约记录(分页)")
|
@GetResource(name = "性格分析1v1咨询预约记录(分页)", path = "/userMentalAppointmentPage")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageNo", value = "当前页数", dataTypeClass = Integer.class, defaultValue = "1"),
|
@ApiImplicitParam(name = "pageSize", value = "分页条数", dataTypeClass = Integer.class, defaultValue = "20"),
|
@ApiImplicitParam(name = "userId", value = "用户ID", dataTypeClass = Long.class),
|
@ApiImplicitParam(name = "name", value = "咨询师姓名", dataTypeClass = String.class),
|
@ApiImplicitParam(name = "telephone", value = "咨询师电话", dataTypeClass = String.class),
|
@ApiImplicitParam(name = "statusFlag", value = "状态:1预约中,2服务中,3已完成,9已取消", dataTypeClass = Integer.class),
|
})
|
public ResponseData<PageResult<UserMentalAppointmentPageResponseDTO>> userMentalAppointmentPage(Integer pageNo, Integer pageSize, Long userId, String name, String telephone, Integer statusFlag) {
|
Page<UserMentalAppointmentPageResponseDTO> page = mentalAppointmentService.userMentalAppointmentPage(
|
PageFactory.page(pageNo, pageSize),
|
userId,
|
name,
|
telephone,
|
statusFlag
|
);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(page));
|
}
|
|
|
@ApiOperation("根据用户id分页查询预约记录")
|
@GetResource(name = "根据用户id分页查询预约记录", path = "/counsellingInfo/getCounsellingOrderReservationByUserId", requiredPermission = false)
|
public ResponseData<PageResult<CounsellingOrderReservationResponseDTO>> getCounsellingOrderReservationByUserId(UserCounsellingOrderReservationRequestDTO req) {
|
// 根据用户id查询预约记录
|
Page<CounsellingOrderReservation> page = this.counsellingOrderReservationService.findOrderReservationByUserIdPage(PageFactory.defaultPage(req), req);
|
if (CollectionUtil.isNotEmpty(page.getRecords())){
|
List<CounsellingOrderReservationResponseDTO> list = BeanUtil.copyToList(page.getRecords(),CounsellingOrderReservationResponseDTO.class);
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(list,page.getTotal(), Convert.toInt(page.getSize()),Convert.toInt(page.getCurrent())));
|
}
|
return new SuccessResponseData<>(PageResultFactory.createPageResult(Lists.newArrayList(),page.getTotal(), Convert.toInt(page.getSize()),Convert.toInt(page.getCurrent())));
|
}
|
|
@ApiOperation("根据用户id查询咨询课时统计")
|
@GetResource(name = "根据用户id查询咨询课时统计", path = "/counsellingInfo/getCounsellingNumTotalByUserId", requiredPermission = false)
|
public ResponseData<UserCounsellingTotalDTO> getCounsellingNumTotalByUserId(UserCounsellingOrderReservationRequestDTO userCounsellingOrderReservationRequestDTO) {
|
|
return new SuccessResponseData<>(this.counsellingOrderReservationService.getCounsellingNumTotalByUserId(userCounsellingOrderReservationRequestDTO));
|
}
|
}
|