diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskImeiRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskImeiRepository.java index 97cf61de..eefc7d45 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskImeiRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskImeiRepository.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository; import java.util.Date; import java.util.List; +import java.util.Set; /** * @author jt @@ -18,6 +19,7 @@ import java.util.List; public interface TaskImeiRepository extends JpaRepository, JpaSpecificationExecutor { /** * 任务id查找 + * * @param taskId * @return */ @@ -25,6 +27,7 @@ public interface TaskImeiRepository extends JpaRepository, JpaSp /** * 状态查找 + * * @param num * @return */ @@ -59,11 +62,21 @@ public interface TaskImeiRepository extends JpaRepository, JpaSp /** * 统计今天数量 + * * @param userId * @param num * @return */ @Query(value = "select count(1) from tb_task_imei where" + " to_days(create_time) = to_days(now()) and user_id = ?1 and status = ?2", nativeQuery = true) - Integer countByUserId( Long userId, Integer num); + Integer countByUserId(Long userId, Integer num); + + /** + * 删除所有imei + * + * @param taskIds 任务id + */ + @Modifying + @Query(value = "delete from tb_task_imei where task_id in ?1", nativeQuery = true) + void deleteByTaskIds(Set taskIds); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskTagRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskTagRepository.java index 44034718..24702c55 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskTagRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/TaskTagRepository.java @@ -3,9 +3,12 @@ package com.baiye.modules.platform.repository; import com.baiye.modules.platform.domain.TaskTag; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Set; /** * @author jt @@ -22,8 +25,18 @@ public interface TaskTagRepository extends JpaRepository, JpaSpec /** * 根据任务id查询tag + * * @param taskId * @return */ TaskTag findTaskTagByTaskId(Long taskId); + + /** + * 删除所有imei + * + * @param taskIds 任务id + */ + @Modifying + @Query(value = "delete from tb_task_tag where task_id in ?1", nativeQuery = true) + void deleteByTaskIds(Set taskIds); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java index 1b4a6dc3..3287b850 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskImeiService.java @@ -4,6 +4,7 @@ import com.baiye.modules.platform.domain.TaskImei; import com.baiye.modules.platform.service.dto.PlatformTransmitDTO; import java.util.List; +import java.util.Set; /** * @author Enzo @@ -60,4 +61,10 @@ public interface TaskImeiService { * @return */ Integer countByUserIdAndDate(Long userId, Integer num); + + /** + * 删除所有的Imei(删除公司) + * @param taskIds + */ + void deleteTaskImei(Set taskIds); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java index 468ba293..0c3e06c3 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskImeiServiceImpl.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Set; /** * @author Enzo @@ -87,5 +88,10 @@ public class TaskImeiServiceImpl implements TaskImeiService { return taskImeiRepository.countByUserId(userId, num); } + @Override + public void deleteTaskImei(Set taskIds) { + taskImeiRepository.deleteByTaskIds(taskIds); + } + } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/TaskReportRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/TaskReportRepository.java index d0f312af..78e7b11b 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/TaskReportRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/TaskReportRepository.java @@ -3,6 +3,7 @@ package com.baiye.modules.report.dao; import com.baiye.modules.report.entity.TaskReport; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -36,4 +37,7 @@ public interface TaskReportRepository extends JpaRepository, J */ @Query(value = "select * from tb_report_task where (create_time between ?1 and ?2) and company_id =?3", nativeQuery = true) List queryAllByTimeAndCompanyId(String beginTime, String endTime, Long companyId); + + @Modifying + void deleteByCompanyId(Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/UserReportRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/UserReportRepository.java index 35333e36..3b923b38 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/UserReportRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/UserReportRepository.java @@ -3,6 +3,7 @@ package com.baiye.modules.report.dao; import com.baiye.modules.report.entity.UserReport; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -36,4 +37,7 @@ public interface UserReportRepository extends JpaRepository, J */ @Query(value = "select * from tb_report_user where (create_time between ?1 and ?2) and (coalesce (?3,null) is null or organize_id in (?3))", nativeQuery = true) List queryAllByTimeAndTeamIds(String beginTime, String endTime, List ids); + + @Modifying + void deleteByCompanyId(Long companyId); } \ No newline at end of file diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/QueryReportService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/QueryReportService.java index f970c381..030549c4 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/QueryReportService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/QueryReportService.java @@ -108,7 +108,12 @@ public interface QueryReportService { */ void downloadCallRecordDetails(HttpServletResponse response, Long clueId); + Map> findMemberIdByOrganizeIds(List organizeIds); - - Map> findMemberIdByOrganizeIds(List organizeIds); + /** + * 删除所有的统计信息 + * + * @param companyId + */ + void deleteReport(Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/impl/QueryReportServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/impl/QueryReportServiceImpl.java index 51f63dca..338d09dc 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/impl/QueryReportServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/service/impl/QueryReportServiceImpl.java @@ -50,6 +50,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.util.*; @@ -922,4 +923,11 @@ public class QueryReportServiceImpl implements QueryReportService { } return map; } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteReport(Long companyId) { + taskReportRepository.deleteByCompanyId(companyId); + userReportRepository.deleteByCompanyId(companyId); + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java index 00d10346..d5c2bb6d 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java @@ -37,6 +37,9 @@ import com.baiye.model.enums.ResponseCode; import com.baiye.modules.platform.domain.*; import com.baiye.modules.platform.repository.*; import com.baiye.modules.platform.service.*; +import com.baiye.modules.platform.service.dto.*; +import com.baiye.modules.report.service.QueryReportService; +import com.baiye.modules.system.mapstruct.UserMapper; import com.baiye.modules.platform.service.dto.BuyComboDTO; import com.baiye.modules.platform.service.dto.CompanyDto; import com.baiye.modules.platform.service.dto.CreateUserDTO; @@ -48,17 +51,20 @@ import com.baiye.modules.system.mapstruct.UserMapper; import com.baiye.modules.system.repository.RoleRepository; import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.system.service.UserService; +import com.baiye.modules.telemarkting.service.ExtensionNumberService; import com.baiye.util.*; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.cache.Cache; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -125,6 +131,12 @@ public class UserServiceImpl implements UserService { + private final CallDeductService callDeductService; + private final LabelOrganizeService labelOrganizeService; + private final ExtensionNumberService extensionNumberService; + private final QueryReportService queryReportService; + private final TaskImeiService taskImeiService; + private final TaskTagRepository taskTagRepository; @Override @Transactional(rollbackFor = Exception.class) public Boolean fileCreateUser(List excels, Long companyId, UserDto userDto) { @@ -599,6 +611,13 @@ public class UserServiceImpl implements UserService { // 踢出用户 this.remoteAuthService.delete(Sets.newHashSet(userIds)); //TODO 删除逻辑待补充? + //11、删除分机号 + extensionNumberService.deleteExtensionNumberByCompany(user.getCompanyId()); + //12、删除统计信息 + queryReportService.deleteReport(user.getCompanyId()); + //13.删除imei和tag + taskImeiService.deleteTaskImei(taskIds); + taskTagRepository.deleteByTaskIds(taskIds); return; } else if (roleIds.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) { // 二: 删除或者替换组长 @@ -607,18 +626,15 @@ public class UserServiceImpl implements UserService { throw new BadRequestException("请选择组长角色的用户"); organizeUserRepository.updateUser(userId, replaceUserId); organizeUserRepository.updateCreateBy(replaceUserId, userId); - this.sourceDel(isDel, userId, replaceUserId); + this.sourceDel(userId, replaceUserId); } else if (roleIds.contains(RoleNumberConstants.MINUS_FIVE_NUMBER)) { // 三: 删除或者替换业务员 - if (isDel) organizeUserRepository.deleteByUserId(userId); - else { - if (replaceUserId == null) throw new BadRequestException("请选择替换人员"); - if (CollUtil.isNotEmpty(replaceRoleIds) && !roleIds.contains(RoleNumberConstants.MINUS_FIVE_NUMBER)) - throw new BadRequestException("请选择业务管理员角色的用户"); - organizeUserRepository.updateUser(userId, replaceUserId); - } - this.sourceDel(isDel, userId, replaceUserId); + if (replaceUserId == null) organizeUserRepository.deleteByUserId(userId); + else organizeUserRepository.updateUser(userId, replaceUserId); + this.sourceDel(userId, replaceUserId); } + //分机号 + extensionNumberService.updateExtensionNumber(userId, replaceUserId); // 清理缓存 delCaches(userId, user.getUsername()); // 踢出用户 @@ -626,8 +642,8 @@ public class UserServiceImpl implements UserService { userRepository.deleteById(userId); } - private void sourceDel(Boolean isDel, Long userId, Long replaceUserId) { - if (isDel) { + private void sourceDel(Long userId, Long replaceUserId) { + if (replaceUserId == null) { ResponseEntity> response = sourceClueClient.delClueByUser(userId); if (response.getStatusCode().value() != 200) throw new BadRequestException("删除失败"); //更新任务资源数量 diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionDisplayRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionDisplayRepository.java index 67f3fc5c..15508a0d 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionDisplayRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionDisplayRepository.java @@ -3,6 +3,7 @@ package com.baiye.modules.telemarkting.dao; import com.baiye.modules.telemarkting.entity.ExtensionDisplay; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.stereotype.Repository; @Repository @@ -15,4 +16,11 @@ public interface ExtensionDisplayRepository extends JpaRepository userIds); + /** + * 用户id删除用户和分机号关联 + * + * @param userId + * @return + */ + @Modifying + @Query(value = "delete from tb_extension_user where member_id = ?1", nativeQuery = true) + int deleteByMemberId(Long userId); + @Modifying @Query(value = "update ExtensionUser c set c.memberId =?2 where c.memberId = ?1") void updateByNumber(Long userId, Long replaceUserId); + + /** + * 删除公司。所有关联分机号 + * + * @param companyId + */ + @Modifying + @Query(value = "delete from tb_extension_user where number in (select number from tb_extension_number where company_id = ?1)", nativeQuery = true) + void deleteByCompanyId(Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/ExtensionNumberService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/ExtensionNumberService.java index 2d6089a7..6fd94462 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/ExtensionNumberService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/ExtensionNumberService.java @@ -12,7 +12,7 @@ import org.springframework.web.multipart.MultipartFile; */ public interface ExtensionNumberService { - CommonResponse addNumbers(MultipartFile file, Long display, Long dyDisplay, Long deliveryDisplay,Long tokerDisplay, Long companyId); + CommonResponse addNumbers(MultipartFile file, Long display, Long dyDisplay, Long deliveryDisplay, Long tokerDisplay, Long companyId); ExtensionNumber getExtension(Long memberId); @@ -39,4 +39,19 @@ public interface ExtensionNumberService { * @return */ ExtensionDisplay queryExtensionDisplay(Long companyId); + + /** + * 删除分机号 + * + * @param companyId 公司id + */ + void deleteExtensionNumberByCompany(Long companyId); + + /** + * 组员替换 或修改 + * + * @param userId 组员id + * @param replaceUserId 替换者id + */ + void updateExtensionNumber( Long userId, Long replaceUserId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ExtensionNumberServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ExtensionNumberServiceImpl.java index e6887bfb..1ea2e11c 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ExtensionNumberServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/ExtensionNumberServiceImpl.java @@ -159,4 +159,28 @@ public class ExtensionNumberServiceImpl implements ExtensionNumberService { public ExtensionDisplay queryExtensionDisplay(Long companyId) { return extensionDisplayRepository.findExtensionDisplayByCompanyId(companyId); } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteExtensionNumberByCompany(Long companyId) { + extensionUserRepository.deleteByCompanyId(companyId); + extensionNumberRepository.deleteByCompanyId(companyId); + extensionDisplayRepository.deleteByCompanyId(companyId); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateExtensionNumber(Long userId, Long replaceUserId) { + if (replaceUserId == null) { + //删除组员 + extensionNumberRepository.updateExtensionNumber(0, userId); + extensionUserRepository.deleteByMemberId(userId); + } else { + extensionUserRepository.updateByNumber(userId, replaceUserId); + int i = extensionNumberRepository.updateExtensionNumber(0, replaceUserId); + if (i > 0) { + extensionUserRepository.deleteByMemberId(replaceUserId); + } + } + } } diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/DelUserDTO.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/DelUserDTO.java index ca53b2c4..6af88c34 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/dto/DelUserDTO.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/DelUserDTO.java @@ -11,7 +11,4 @@ public class DelUserDTO { @ApiModelProperty("替换人用户ID") private Long replaceUserId; - - @ApiModelProperty("是否删除资源") - private Boolean isDel; } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerRepository.java index a84001c9..c6d84418 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerRepository.java @@ -1,13 +1,14 @@ package com.baiye.module.dao; -import com.baiye.module.entity.ClueMiddle; import com.baiye.module.entity.ReportToker; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Set; /** * @author jt @@ -36,4 +37,8 @@ public interface ReportTokerRepository extends JpaRepository, */ @Query(value = "select * from tb_report_toker where (create_time between ?1 and ?2) and member_id in ?3", nativeQuery = true) List queryAllByTimeAndMemberIds(String beginTime, String endTime, List memberIds); + + @Modifying + @Query(value = "delete from tb_report_toker where task_id in ?1", nativeQuery = true) + void deleteTokerReport(Set taskIds); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java index ef248c2a..b9c7b807 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java @@ -66,7 +66,7 @@ public class ClueServiceImpl implements ClueService { private final CompanyService companyService; private final TurnCrmLogRepository turnCrmLogRepository; - + private final ReportTokerRepository reportTokerRepository; private final ClueBackupsTask clueBackupsTask; private static final SimpleDateFormat timeOne = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -509,6 +509,9 @@ public class ClueServiceImpl implements ClueService { clueFailRecordRepository.deleteAllByRecordIdIn(clueRecordId); //5、删除拓客或者DMP资源数据 clueTalkRepository.deleteByTaskIdIn(taskIds); + //6、删除拓客投流的统计 + reportTokerRepository.deleteTokerReport(taskIds); + //7. } return true; } @@ -530,7 +533,7 @@ public class ClueServiceImpl implements ClueService { return clueMiddleRepository.findTaskIdCount(taskIds); } - public void delete(List clueAll, Set clueIds){ + public void delete(List clueAll, Set clueIds) { //1、备份数据 clueBackupsTask.clueBackups(clueAll); //2、删除资源数据 diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java index d7c7be37..672af714 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java @@ -24,7 +24,7 @@ public class CrmTurnoverSync { /** * 每天凌晨 0点半,查看金额成交情况 */ -// @Scheduled(cron = "0 0/5 * * * ? ") + // @Scheduled(cron = "0 0/5 * * * ? ") @Scheduled(cron = "0 30 0 * * ? ") public void dealTurnover() { log.info("-------------------检测成交金额记录-------------");