| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- package com.jtzx.crm.module.sys.service;
- import cc.uncarbon.framework.core.context.UserContextHolder;
- import cc.uncarbon.framework.core.exception.BusinessException;
- import cc.uncarbon.framework.core.page.PageParam;
- import cc.uncarbon.framework.core.page.PageResult;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.text.CharSequenceUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.jtzx.crm.module.sys.entity.SysCustomerDataEntity;
- import com.jtzx.crm.module.sys.entity.SysCustomerFollowEntity;
- import com.jtzx.crm.module.sys.entity.SysParamBaseDataEntity;
- import com.jtzx.crm.module.sys.mapper.SysCustomerDataMapper;
- import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
- import com.jtzx.crm.module.sys.mapper.SysParamBaseDataMapper;
- import com.jtzx.crm.module.sys.model.request.*;
- import com.jtzx.crm.module.sys.model.response.*;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.time.format.DateTimeFormatter;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Objects;
- /**
- * 公海客户(学校)数据
- */
- @RequiredArgsConstructor
- @Service
- @Slf4j
- public class SysCustomerDataPublicService {
- private final SysCustomerDataMapper sysCustomerDataMapper;
- private final SysParamBaseDataMapper sysParamBaseDataMapper;
- private final SysCustomerUserCommonService sysCustomerUserCommonService;
- private final SysCustomerDataService sysCustomerDataService;
- private final SysCustomerPersonService sysCustomerPersonService;
- private final SysCustomerDataFollowService sysCustomerDataFollowService;
- private final SysCustomerFollowService sysCustomerFollowService;
- private final SysCustomerOperLogService sysCustomerOperLogService;
- /**
- * 查询公海客户页面顶部筛选条件数据
- *
- * @return
- */
- public SysCustomerPublicSelectBO queryHeadSelectData() {
- //返回数据对象
- SysCustomerPublicSelectBO resultData = SysCustomerPublicSelectBO.builder().build();
- //学段信息
- resultData.setStageData(sysCustomerUserCommonService.handleStageData());
- //省市信息
- SysCustomerSelectBO sysCustomerSelectBO = sysCustomerUserCommonService.querySelectDataByType1(true, false);
- if (sysCustomerSelectBO != null) {
- resultData.setRegionData(sysCustomerSelectBO.getRegionData());
- }
- return resultData;
- }
- /**
- * 后台管理-公海客户(学校)分页列表
- */
- public PageResult<SysCustomerDataPublicBO> adminList(AdminSysCustomerDataPublicListDTO dto) {
- Page<SysCustomerDataEntity> entityPage = sysCustomerDataMapper.selectPage(
- new Page<>(dto.getPageNum(), dto.getPageSize()),
- new QueryWrapper<SysCustomerDataEntity>()
- .lambda()
- // 名称
- .like(CharSequenceUtil.isNotBlank(dto.getQueryStr()), SysCustomerDataEntity::getName, CharSequenceUtil.cleanBlank(dto.getQueryStr()))
- // 学段id(param_base_data表主id)
- .eq(Objects.nonNull(dto.getStageId()), SysCustomerDataEntity::getStageId, dto.getStageId())
- // 省份id(省份表主id)
- .eq(Objects.nonNull(dto.getProvinceId()), SysCustomerDataEntity::getProvinceId, dto.getProvinceId())
- // 城市id(不为空时)
- .eq(Objects.nonNull(dto.getCityId()), SysCustomerDataEntity::getCityId, dto.getCityId())
- // 城市id(为空时)
- .in(Objects.isNull(dto.getCityId()), SysCustomerDataEntity::getCityId, sysCustomerUserCommonService.queryUserCityIds(dto.getProvinceId()))
- //认领状态
- .eq(SysCustomerDataEntity::getClaimStatus, 0)
- // 排序
- .orderByDesc(SysCustomerDataEntity::getCreatedAt)
- );
- return this.entityPage2BOPage(entityPage);
- }
- /**
- * 新增公海客户
- *
- * @param dto
- */
- @Transactional(rollbackFor = Exception.class)
- public void adminInsertCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- sysCustomerDataService.adminInsert(dto);
- }
- /**
- * 公海客户修改
- *
- * @param dto
- */
- @Transactional(rollbackFor = Exception.class)
- public void adminUpdateCustomerData(AdminSysCustomerDataInsertOrUpdateDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- sysCustomerDataService.adminUpdate(dto);
- }
- /**
- * 删除公海客户
- *
- * @param id
- */
- @Transactional(rollbackFor = Exception.class)
- public void adminDeleteCustomerData(Long id) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- sysCustomerDataService.adminDelete(id);
- }
- /**
- * 公海认领客户
- *
- * @param customerId
- */
- @Transactional(rollbackFor = Exception.class)
- public void claimCustomer(Long customerId) {
- sysCustomerDataService.claimCustomer(customerId);
- }
- /**
- * 公海添加客户联系人
- *
- * @param dto
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public void adminInsertCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- sysCustomerPersonService.adminInsert(dto);
- }
- /**
- * 公海修改客户联系人
- *
- * @param dto
- */
- @Transactional(rollbackFor = Exception.class)
- public void adminUpdateCustomerPerson(AdminSysCustomerPersonInsertOrUpdateDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- sysCustomerPersonService.adminUpdate(dto);
- }
- /**
- * 公海删除联系人
- *
- * @param id
- */
- @Transactional(rollbackFor = Exception.class)
- public void adminDeleteCustomerPerson(Long id) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- sysCustomerPersonService.adminDelete(id);
- }
- /**
- * 查询公海客户联系人
- */
- public List<SysCustomerPersonBO> adminListCustomerPerson(CustomerPersonReqDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- return sysCustomerPersonService.adminList(dto);
- }
- /**
- * 查询公海客户详情的信息总览
- *
- * @param dto
- */
- public SysCustomerDetailBO queryCustomerDetail(AdminSysCustomerFollowReqDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- SysCustomerDetailBO detailBO = SysCustomerDetailBO.builder().build();
- //顶部筛选条件数据
- SysCustomerFollowHistorySelectBO publicCustomerSelectData = sysCustomerDataFollowService.queryCustomerFollowSelectCommonData(dto.getCustomerId(), null);
- detailBO.setSelectData(publicCustomerSelectData);
- //客户详情信息
- PageResult<SysCustomerFollowListBO> dataPageList = sysCustomerDataFollowService.queryCustomerFollowDataCommonByPage(dto);
- detailBO.setDataPageList(dataPageList);
- //信息总览
- detailBO.setProductOverviewData(sysCustomerFollowService.queryProductOverViewData(dto.getCustomerId()));
- //跟进记录总览
- detailBO.setFollowOverViewData(sysCustomerFollowService.handleCustomerFollowOverViewData(dto.getCustomerId(), null));
- return detailBO;
- }
- /**
- * 操作日志列表查询
- */
- public SysCustomerOperLogDataBO queryOperLogData(AdminSysCustomerOperLogListDTO dto) {
- if (CollUtil.isEmpty(UserContextHolder.getUserContext().getRoles()) || !UserContextHolder.getUserContext().getRoles().contains("Admin")) {
- throw new BusinessException(400, "无权操作");
- }
- return sysCustomerOperLogService.adminList(dto, false, false);
- }
- /*
- ----------------------------------------------------------------
- 私有方法 private methods
- ----------------------------------------------------------------
- */
- /**
- * 实体分页转 BO 分页
- *
- * @param entityPage 实体分页
- * @return BO 分页
- */
- private PageResult<SysCustomerDataPublicBO> entityPage2BOPage(Page<SysCustomerDataEntity> entityPage) {
- return new PageResult<SysCustomerDataPublicBO>()
- .setCurrent(entityPage.getCurrent())
- .setSize(entityPage.getSize())
- .setTotal(entityPage.getTotal())
- .setRecords(this.entityList2BOs(entityPage.getRecords()));
- }
- /**
- * 实体 List 转 BO List
- *
- * @param entityList 实体 List
- * @return BO List
- */
- private List<SysCustomerDataPublicBO> entityList2BOs(List<SysCustomerDataEntity> entityList) {
- if (CollUtil.isEmpty(entityList)) {
- return Collections.emptyList();
- }
- //查询学段
- List<Long> stageIds =
- entityList.stream()
- .map(SysCustomerDataEntity::getStageId)
- .filter(Objects::nonNull).distinct().toList();
- List<SysParamBaseDataEntity> stageDataList = sysParamBaseDataMapper.selectByIds(stageIds);
- // 深拷贝
- List<SysCustomerDataPublicBO> ret = new ArrayList<>(entityList.size());
- entityList.forEach(
- entity -> {
- SysCustomerDataPublicBO bo = this.entity2BO(entity);
- if (CollUtil.isNotEmpty(stageDataList)) {
- stageDataList.stream()
- .filter(x -> x.getId().equals(entity.getStageId()))
- .findFirst()
- .ifPresent(e -> bo.setStageName(e.getTitle()));
- }
- ret.add(bo);
- });
- return ret;
- }
- /**
- * 实体转 BO
- *
- * @param entity 实体
- * @return BO
- */
- private SysCustomerDataPublicBO entity2BO(SysCustomerDataEntity entity) {
- if (entity == null) {
- return null;
- }
- SysCustomerDataPublicBO bo = new SysCustomerDataPublicBO();
- BeanUtil.copyProperties(entity, bo);
- // 可以在此处为BO填充字段
- bo.setUnUsedDayCount("1天");
- long days = DateUtil.betweenDay(DateUtil.date(),
- DateUtil.parse(entity.getResetDatetime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))),
- false);
- //向上取整
- double ceilDays = Math.ceil(days);
- if ((int) ceilDays >= 1) {
- bo.setUnUsedDayCount(days + "天");
- }
- bo.setDelStatus(true);
- return bo;
- }
- }
|