|
|
@@ -1,25 +1,29 @@
|
|
|
package com.jtzx.crm.module.sys.service;
|
|
|
|
|
|
-import cc.uncarbon.framework.core.constant.HelioConstant;
|
|
|
+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 cc.uncarbon.framework.crud.entity.HelioBaseEntity;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.jtzx.crm.module.sys.entity.SysCustomerTodoEntity;
|
|
|
+import com.jtzx.crm.module.sys.mapper.SysCustomerFollowMapper;
|
|
|
import com.jtzx.crm.module.sys.mapper.SysCustomerTodoMapper;
|
|
|
import com.jtzx.crm.module.sys.model.request.AdminSysCustomerTodoInsertOrUpdateDTO;
|
|
|
-import com.jtzx.crm.module.sys.model.request.AdminSysCustomerTodoListDTO;
|
|
|
+import com.jtzx.crm.module.sys.model.response.BindUserBO;
|
|
|
+import com.jtzx.crm.module.sys.model.response.SysCustomerFollowHistorySelectBO;
|
|
|
+import com.jtzx.crm.module.sys.model.response.SysCustomerFollowListBO;
|
|
|
import com.jtzx.crm.module.sys.model.response.SysCustomerTodoBO;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.text.CharSequenceUtil;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -32,74 +36,96 @@ public class SysCustomerTodoService {
|
|
|
|
|
|
private final SysCustomerTodoMapper sysCustomerTodoMapper;
|
|
|
|
|
|
+ private final SysCustomerFollowMapper sysCustomerFollowMapper;
|
|
|
|
|
|
- /**
|
|
|
- * 后台管理-分页列表
|
|
|
- */
|
|
|
- public PageResult<SysCustomerTodoBO> adminList(PageParam pageParam, AdminSysCustomerTodoListDTO dto) {
|
|
|
- Page<SysCustomerTodoEntity> entityPage = sysCustomerTodoMapper.selectPage(
|
|
|
- new Page<>(pageParam.getPageNum(), pageParam.getPageSize()),
|
|
|
- new QueryWrapper<SysCustomerTodoEntity>()
|
|
|
- .lambda()
|
|
|
- // 认领人(跟进)id
|
|
|
- .eq(Objects.nonNull(dto.getClaimUserId()), SysCustomerTodoEntity::getClaimUserId, dto.getClaimUserId())
|
|
|
- // 认领人(跟进)名称
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getClaimUserName()), SysCustomerTodoEntity::getClaimUserName, CharSequenceUtil.cleanBlank(dto.getClaimUserName()))
|
|
|
- // 认领人员所在的项目组id
|
|
|
- .eq(Objects.nonNull(dto.getClaimUserGroupId()), SysCustomerTodoEntity::getClaimUserGroupId, dto.getClaimUserGroupId())
|
|
|
- // 跟进(待办)内容
|
|
|
- .like(CharSequenceUtil.isNotBlank(dto.getFollowContent()), SysCustomerTodoEntity::getFollowContent, CharSequenceUtil.cleanBlank(dto.getFollowContent()))
|
|
|
- // 待办时间
|
|
|
- .eq(Objects.nonNull(dto.getOrderDatetime()), SysCustomerTodoEntity::getOrderDatetime, dto.getOrderDatetime())
|
|
|
- // 时间区间
|
|
|
- .between(Objects.nonNull(dto.getBeginAt()) && Objects.nonNull(dto.getEndAt()), SysCustomerTodoEntity::getCreatedAt, dto.getBeginAt(), dto.getEndAt())
|
|
|
- // 排序
|
|
|
- .orderByDesc(SysCustomerTodoEntity::getCreatedAt)
|
|
|
- );
|
|
|
+ private final SysCustomerDataFollowService sysCustomerDataFollowService;
|
|
|
|
|
|
- return this.entityPage2BOPage(entityPage);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * 根据 ID 取详情
|
|
|
+ * 待办页面查询顶部筛选条件数据
|
|
|
*
|
|
|
- * @param id 主键ID
|
|
|
- * @return null or BO
|
|
|
+ * @return
|
|
|
*/
|
|
|
- public SysCustomerTodoBO getOneById(Long id) {
|
|
|
- return this.getOneById(id, false);
|
|
|
+ public List<BindUserBO> queryMemberData() {
|
|
|
+ List<SysCustomerTodoEntity> todoEntityList =
|
|
|
+ sysCustomerTodoMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerTodoEntity.class)
|
|
|
+ .select(
|
|
|
+ SysCustomerTodoEntity::getClaimUserId,
|
|
|
+ SysCustomerTodoEntity::getClaimUserName
|
|
|
+ )
|
|
|
+ .eq(SysCustomerTodoEntity::getOrderStatus, 0)
|
|
|
+ .orderByDesc(HelioBaseEntity::getCreatedAt)
|
|
|
+ );
|
|
|
+ List<BindUserBO> ret = Lists.newArrayList();
|
|
|
+ SysCustomerFollowHistorySelectBO sysCustomerFollowHistorySelectBO = sysCustomerDataFollowService.queryCustomerOrderSelectData(1, false);
|
|
|
+ if (sysCustomerFollowHistorySelectBO != null && CollUtil.isNotEmpty(sysCustomerFollowHistorySelectBO.getMemberData())) {
|
|
|
+ ret.addAll(sysCustomerFollowHistorySelectBO.getMemberData());
|
|
|
+ if (CollUtil.isNotEmpty(todoEntityList)) {
|
|
|
+ todoEntityList.forEach(
|
|
|
+ entity -> {
|
|
|
+ if (CollUtil.isEmpty(ret) || ret.stream().noneMatch(bo -> bo.getId().equals(entity.getClaimUserId()))) {
|
|
|
+ BindUserBO bo = new BindUserBO();
|
|
|
+ bo.setId(entity.getClaimUserId());
|
|
|
+ bo.setUsername(entity.getClaimUserName());
|
|
|
+ ret.add(bo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据 ID 取详情
|
|
|
+ * 根据条件查询待办列表
|
|
|
*
|
|
|
- * @param id 主键ID
|
|
|
- * @param throwIfInvalidId 是否在 ID 无效时抛出异常
|
|
|
- * @return null or BO
|
|
|
+ * @param startDateTime
|
|
|
+ * @param endDateTime
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
*/
|
|
|
- public SysCustomerTodoBO getOneById(Long id, boolean throwIfInvalidId) throws BusinessException {
|
|
|
- SysCustomerTodoEntity entity = sysCustomerTodoMapper.selectById(id);
|
|
|
- if (throwIfInvalidId && entity == null) {
|
|
|
- throw new BusinessException(400, "无效自定义待办信息数据ID");
|
|
|
+ public List<SysCustomerFollowListBO> queryList(LocalDateTime startDateTime, LocalDateTime endDateTime,
|
|
|
+ Long userId) {
|
|
|
+ List<SysCustomerTodoEntity> todoEntityList =
|
|
|
+ sysCustomerTodoMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<>(SysCustomerTodoEntity.class)
|
|
|
+ .eq(userId != null, SysCustomerTodoEntity::getClaimUserId, userId)
|
|
|
+ .eq(SysCustomerTodoEntity::getOrderStatus, 0)//关闭的自定义待办不查询
|
|
|
+ .ge(startDateTime != null, SysCustomerTodoEntity::getOrderDatetime, startDateTime)
|
|
|
+ .le(endDateTime != null, SysCustomerTodoEntity::getOrderDatetime, endDateTime)
|
|
|
+ );
|
|
|
+
|
|
|
+ List<SysCustomerFollowListBO> sysCustomerFollowListBOS = sysCustomerDataFollowService.queryCustomerFollowOrderData(startDateTime, endDateTime, userId, null, null, 1);
|
|
|
+ if (CollUtil.isNotEmpty(todoEntityList)) {
|
|
|
+ todoEntityList.forEach(
|
|
|
+ entity -> {
|
|
|
+ SysCustomerFollowListBO bo = new SysCustomerFollowListBO();
|
|
|
+ bo.setId(entity.getId());
|
|
|
+ bo.setClaimUserName(entity.getClaimUserName());
|
|
|
+ bo.setFollowContent(entity.getFollowContent());
|
|
|
+ bo.setClaimDatetime(entity.getCreatedAt());
|
|
|
+ bo.setOrderDatetime(entity.getOrderDatetime());
|
|
|
+ bo.setOrderStatus(entity.getOrderStatus());
|
|
|
+ bo.setOrderType(1);
|
|
|
+ bo.setType(1);
|
|
|
+ sysCustomerFollowListBOS.add(bo);
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
-
|
|
|
- return this.entity2BO(entity);
|
|
|
+ return sysCustomerFollowListBOS;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 后台管理-新增
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Long adminInsert(AdminSysCustomerTodoInsertOrUpdateDTO dto) {
|
|
|
log.info("[后台管理-自定义待办信息数据-新增] >> DTO={}", dto);
|
|
|
- this.checkExistence(dto);
|
|
|
-
|
|
|
- dto.setId(null);
|
|
|
SysCustomerTodoEntity entity = new SysCustomerTodoEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
-
|
|
|
+ entity.setClaimUserId(UserContextHolder.getUserId());
|
|
|
+ entity.setClaimUserName(UserContextHolder.getUserName());
|
|
|
sysCustomerTodoMapper.insert(entity);
|
|
|
-
|
|
|
return entity.getId();
|
|
|
}
|
|
|
|
|
|
@@ -109,11 +135,8 @@ public class SysCustomerTodoService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void adminUpdate(AdminSysCustomerTodoInsertOrUpdateDTO dto) {
|
|
|
log.info("[后台管理-自定义待办信息数据-编辑] >> DTO={}", dto);
|
|
|
- this.checkExistence(dto);
|
|
|
-
|
|
|
SysCustomerTodoEntity entity = new SysCustomerTodoEntity();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
-
|
|
|
sysCustomerTodoMapper.updateById(entity);
|
|
|
}
|
|
|
|
|
|
@@ -121,9 +144,18 @@ public class SysCustomerTodoService {
|
|
|
* 后台管理-删除
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void adminDelete(Collection<Long> ids) {
|
|
|
- log.info("[后台管理-自定义待办信息数据-删除] >> ids={}", ids);
|
|
|
- sysCustomerTodoMapper.deleteByIds(ids);
|
|
|
+ public void adminDelete(Long id) {
|
|
|
+ log.info("[后台管理-自定义待办信息数据-删除] >> id={}", id);
|
|
|
+ sysCustomerTodoMapper.deleteById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭待办信息数据
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ public void cancelTodoStatus(Long id) {
|
|
|
+ sysCustomerTodoMapper.deleteById(id);
|
|
|
+ sysCustomerFollowMapper.cancelTodoStatus(id);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -166,47 +198,10 @@ public class SysCustomerTodoService {
|
|
|
// 深拷贝
|
|
|
List<SysCustomerTodoBO> ret = new ArrayList<>(entityList.size());
|
|
|
entityList.forEach(
|
|
|
- entity -> ret.add(this.entity2BO(entity))
|
|
|
+ entity -> ret.add(this.entity2BO(entity))
|
|
|
);
|
|
|
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 实体分页转 BO 分页
|
|
|
- *
|
|
|
- * @param entityPage 实体分页
|
|
|
- * @return BO 分页
|
|
|
- */
|
|
|
- private PageResult<SysCustomerTodoBO> entityPage2BOPage(Page<SysCustomerTodoEntity> entityPage) {
|
|
|
- return new PageResult<SysCustomerTodoBO>()
|
|
|
- .setCurrent(entityPage.getCurrent())
|
|
|
- .setSize(entityPage.getSize())
|
|
|
- .setTotal(entityPage.getTotal())
|
|
|
- .setRecords(this.entityList2BOs(entityPage.getRecords()));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 检查是否已存在同名数据
|
|
|
- *
|
|
|
- * @param dto DTO
|
|
|
- */
|
|
|
- private void checkExistence(AdminSysCustomerTodoInsertOrUpdateDTO dto) {
|
|
|
- /*
|
|
|
- 可以根据自己业务需要,解禁这段代码,修改判断条件和文案
|
|
|
-
|
|
|
- SysCustomerTodoEntity existingEntity = sysCustomerTodoMapper.selectOne(
|
|
|
- new QueryWrapper<SysCustomerTodoEntity>()
|
|
|
- .lambda()
|
|
|
- .select(SysCustomerTodoEntity::getId)
|
|
|
- .eq(SysCustomerTodoEntity::getTitle, dto.getTitle())
|
|
|
- .last(HelioConstant.CRUD.SQL_LIMIT_1)
|
|
|
- );
|
|
|
-
|
|
|
- if (existingEntity != null && !existingEntity.getId().equals(dto.getId())) {
|
|
|
- throw new BusinessException(400, "已存在相同自定义待办信息数据,请重新输入");
|
|
|
- }
|
|
|
- */
|
|
|
- }
|
|
|
-
|
|
|
}
|