diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java index 23959508..2667dcf3 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/constant/RoleNumberConstants.java @@ -17,26 +17,11 @@ public class RoleNumberConstants { */ public static final Long MINUS_ONE_NUMBER = 1L; - /** - * 普通用户 - */ - public static final Long MINUS_TWO_NUMBER = 2L; - - /** - * 业务主管 - */ - public static final Long MINUS_THREE_NUMBER = 3L; - /** * 呼叫业务员 */ public static final Long MINUS_FIVE_NUMBER = 5L; - /** - * 测试角色 - */ - public static final Long MINUS_SEVEN_NUMBER = 7L; - /** * 管理员 */ diff --git a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/MobileUtil.java b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/MobileUtil.java index be3b1f28..5842ad9d 100644 --- a/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/MobileUtil.java +++ b/ad-platform-common/ad-platform-common-core/src/main/java/com/baiye/util/MobileUtil.java @@ -13,9 +13,9 @@ import java.util.regex.Pattern; public class MobileUtil { /** - * 中国电信号码格式验证 手机段: 133,149,153,173,177,180,181,189,191,199,1349,1410,1700,1701,1702 + * 中国电信号码格式验证 手机段: 133,149,153,173,177,180,181,189,191,199,1349,1410,1700,1701,1702,193 **/ - private static final String CHINA_TELECOM_PATTERN = "(?:^(?:\\+86)?1(?:33|49|53|7[37]|8[019]|9[19])\\d{8}$)|(?:^(?:\\+86)?1349\\d{7}$)|(?:^(?:\\+86)?1410\\d{7}$)|(?:^(?:\\+86)?170[0-2]\\d{7}$)"; + private static final String CHINA_TELECOM_PATTERN = "(?:^(?:\\+86)?1(?:33|49|53|7[37]|8[019]|9[139])\\d{8}$)|(?:^(?:\\+86)?1349\\d{7}$)|(?:^(?:\\+86)?1410\\d{7}$)|(?:^(?:\\+86)?170[0-2]\\d{7}$)"; /** * 中国联通号码格式验证 手机段:130,131,132,145,146,155,156,166,171,175,176,185,186,1704,1707,1708,1709 @@ -27,7 +27,7 @@ public class MobileUtil { * 手机段:134,135,136,137,138,139,147,148,150,151,152,157,158,159,178,182,183,184,187,188,195,198,1440,1703,1705,1706 **/ // private static final String CHINA_MOBILE_PATTERN = "(?:^(?:\\+86)?1(?:3[4-9]|4[78]|5[0-27-9]|78|8[2-478]|98|95)\\d{8}$)|(?:^(?:\\+86)?1440\\d{7}$)|(?:^(?:\\+86)?170[356]\\d{7}$)"; - private static final String CHINA_MOBILE_PATTERN = "(?:^(?:\\+86)?1(?:3[4-9]|4[78]|5[0-27-9]|7[28]|8[2-478]|98|95)\\d{8}$)|(?:^(?:\\+86)?1440\\d{7}$)|(?:^(?:\\+86)?170[356]\\d{7}$)"; + private static final String CHINA_MOBILE_PATTERN = "(?:^(?:\\+86)?1(?:3[4-9]|4[78]|5[0-27-9]|6[5]|7[28]|8[2-478]|98|95)\\d{8}$)|(?:^(?:\\+86)?1440\\d{7}$)|(?:^(?:\\+86)?170[356]\\d{7}$)"; /** * 中国大陆手机号码校验 diff --git a/ad-platform-gateway/src/main/resources/config/application.yml b/ad-platform-gateway/src/main/resources/config/application.yml index a5685053..6e9daa82 100644 --- a/ad-platform-gateway/src/main/resources/config/application.yml +++ b/ad-platform-gateway/src/main/resources/config/application.yml @@ -1,7 +1,7 @@ spring: profiles: - active: prod + active: dev cloud: gateway: discovery: diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java index 57011f58..ea33ddb6 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/SourceClueClient.java @@ -96,5 +96,9 @@ public interface SourceClueClient { @PostMapping(API_PREFIX + "/count/memberStatus") @ApiOperation("未分配线索的总条数") CommonResponse> countClueByMemberStatus(@RequestBody ClueQueryCriteria clueQueryCriteria); + + @ApiOperation("根据组员互换所属组") + @PostMapping(API_PREFIX + "/updateClueOrganize") + ResponseEntity updateClueOrganize(@RequestBody Map map); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java index 292f474b..256edd10 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/feign/callback/SourceClueClientFallback.java @@ -97,4 +97,9 @@ public class SourceClueClientFallback implements SourceClueClient { public CommonResponse> countClueByMemberStatus(ClueQueryCriteria clueQueryCriteria) { return null; } + + @Override + public ResponseEntity updateClueOrganize(Map map) { + return null; + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/OrganizeUser.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/OrganizeUser.java index 4467940e..200f2c6f 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/OrganizeUser.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/OrganizeUser.java @@ -5,7 +5,9 @@ import io.swagger.annotations.ApiModelProperty; import javax.persistence.*; import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import org.hibernate.annotations.CreationTimestamp; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -19,9 +21,10 @@ import java.io.Serializable; * @date 2021-12-16 09:21:51 */ @Data +@AllArgsConstructor +@NoArgsConstructor @Entity @Table(name = "tb_organize_user") -@ApiModel(value = "OrganizeUser") @EntityListeners(AuditingEntityListener.class) public class OrganizeUser implements Serializable { @@ -67,4 +70,17 @@ public class OrganizeUser implements Serializable { @ApiModelProperty(value = "更新人") @Column(name = "update_by") private Long updateBy; + + public OrganizeUser(Long organizeId, Long userId, Boolean isLeader) { + this.organizeId = organizeId; + this.userId = userId; + this.isLeader = isLeader; + } + + public OrganizeUser(Long organizeId, Long userId, Boolean isLeader, Long createBy) { + this.organizeId = organizeId; + this.userId = userId; + this.isLeader = isLeader; + this.createBy = createBy; + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TaskOrganize.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TaskOrganize.java index 84bb7d8b..b6692daa 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TaskOrganize.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/TaskOrganize.java @@ -87,8 +87,8 @@ public class TaskOrganize { private String remark; @Transient - @ApiModelProperty(value = "组长昵称") - private String userNickName; + @ApiModelProperty(value = "小组名称") + private String organizeName; @Transient @ApiModelProperty(value = "组员用户信息") diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/OrganizeUserRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/OrganizeUserRepository.java index 38d3b254..349a6674 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/OrganizeUserRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/OrganizeUserRepository.java @@ -13,18 +13,11 @@ public interface OrganizeUserRepository extends JpaRepository findByCreateId(Long currentUserId); @@ -32,8 +25,6 @@ public interface OrganizeUserRepository extends JpaRepository findByOrganizeId(Long id); /** * userId查询 - * - * @param currentUserId - * @return */ OrganizeUser findByUserId(Long currentUserId); /** * userId集合查询 - * - * @param userIds - * @return */ List findByUserIdIn(Set userIds); /** - * 更新组员组长 TODO:2.0版本开发 - * - * @param organizeId - * @param replaceOrganizeId + * userId集合查询 + */ + List findByUserIdIn(List userIds); + + /** + * 更新组员组长 TODO:2.0版本开 */ @Modifying @Query(value = "update tb_organize_user set organize_id = ?2,is_leader = false," + @@ -106,9 +84,6 @@ public interface OrganizeUserRepository extends JpaRepository ?1 ") @@ -118,9 +93,6 @@ public interface OrganizeUserRepository extends JpaRepository findAllIdByOrganizeId(Long organizeId); @@ -139,4 +111,6 @@ public interface OrganizeUserRepository extends JpaRepository findByCreateByOrUserId(Long createBy,Long userId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/OrganizeController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/OrganizeController.java index cb545110..b357aa51 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/OrganizeController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/OrganizeController.java @@ -6,10 +6,7 @@ import com.baiye.model.dto.OrganizeQueryCriteria; import com.baiye.modules.platform.domain.Organize; import com.baiye.modules.platform.domain.OrganizeUser; import com.baiye.modules.platform.service.OrganizeService; -import com.baiye.modules.platform.service.dto.OrganizeMemberDistributionDTO; -import com.baiye.modules.platform.service.dto.OrganizeSaveDTO; -import com.baiye.modules.platform.service.dto.OrganizeUserQueryCriteria; -import com.baiye.modules.platform.service.dto.TaskOrganizeQueryCriteria; +import com.baiye.modules.platform.service.dto.*; import com.baiye.util.ValidList; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -185,4 +182,11 @@ public class OrganizeController { public ResponseEntity> findOrganizeIdByMember(@RequestParam("memberId") Long memberId) { return organizeService.findOrganizeIdByMember(memberId); } + + @PostMapping("/convert") + @ApiOperation("组成员变动") + public CommonResponse convert(@Validated @RequestBody OrganizeConvertDTO organizeConvertDTO) { + organizeService.convert(organizeConvertDTO); + return CommonResponse.createBySuccess(); + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskController.java index fddf0db7..76b3c6e1 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/TaskController.java @@ -101,9 +101,9 @@ public class TaskController { @Inner(value = false) @ApiOperation("websocket发送错误信息") - @GetMapping("/sendErrMessage") - public void sendErrMessage(String errorMessage, Long userId) { - taskService.sendErrMessage(errorMessage, userId); + @GetMapping("/sendMessage") + public void sendMessage(String message, Long userId, String type) { + taskService.sendMessage(message, userId, type); } @GetMapping("/form/encryption") diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/OrganizeService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/OrganizeService.java index 56ca1008..808d1322 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/OrganizeService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/OrganizeService.java @@ -118,6 +118,7 @@ public interface OrganizeService { /** * 查询所有组和未分配用户 + * * @param taskId 查询动态任务分配比率时传 */ Map selectAllOrganizeUser(Long taskId); @@ -132,10 +133,15 @@ public interface OrganizeService { */ Map findNameById(Set organizeIds); - Map> findMemberIdByOrganizeIds(List organizeIds); + Map> findMemberIdByOrganizeIds(List organizeIds); /** * 根据用户id查询组id(有权限查看组员信息,并且是组长) */ ResponseEntity> findOrganizeIdByMember(Long memberId); + + /** + * 组成员变动 + */ + void convert(OrganizeConvertDTO organizeConvertDTO); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskService.java index fb0307ba..b3c3a52e 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/TaskService.java @@ -72,9 +72,9 @@ public interface TaskService { void delTask(Long taskId); /** - * 发送错误信息 + * 发送websocket信息 */ - void sendErrMessage(String errorMessage, Long userId); + void sendMessage(String message, Long userId, String type); void updateTaskEncryption(Long taskId); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeConvertDTO.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeConvertDTO.java new file mode 100644 index 00000000..25d9f691 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeConvertDTO.java @@ -0,0 +1,24 @@ +package com.baiye.modules.platform.service.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; + +@Data +public class OrganizeConvertDTO { + + @NotNull(message = "被替换人不能为空") + @ApiModelProperty("被替换的用户ID") + private Long userId; + + @ApiModelProperty("要移动到具体小组的小组ID") + @NotNull(message = "组ID不能为空") + private Long organizeId; + + @ApiModelProperty("移动到对方组的角色 9:组长 5:组员") + private int roleLevel; + + @ApiModelProperty("替换的用户ID") + private Long replaceUserId; +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeDto.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeDto.java index 06b664a7..1d2c6046 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeDto.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/OrganizeDto.java @@ -17,6 +17,7 @@ import java.util.Map; public class OrganizeDto{ @JsonSerialize(using = ToStringSerializer.class) + @ApiModelProperty(value = "小组ID") private Long id; private String organizeName; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/OrganizeServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/OrganizeServiceImpl.java index b6a3c512..0ad29894 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/OrganizeServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/OrganizeServiceImpl.java @@ -1,6 +1,7 @@ package com.baiye.modules.platform.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.util.ObjectUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.RoleNumberConstants; @@ -17,6 +18,7 @@ import com.baiye.modules.platform.service.dto.*; import com.baiye.modules.platform.service.mapstruct.OrganizeMapper; import com.baiye.modules.platform.service.mapstruct.OrganizeUserMapper; import com.baiye.modules.platform.service.mapstruct.TaskOrganizeMapper; +import com.baiye.modules.system.domain.Role; import com.baiye.modules.system.domain.User; import com.baiye.modules.system.dto.UserQueryCriteria; import com.baiye.modules.system.repository.UserRepository; @@ -40,7 +42,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; -import java.util.stream.Stream; @Service @RequiredArgsConstructor @@ -59,7 +60,6 @@ public class OrganizeServiceImpl implements OrganizeService { private final TaskOrganizeRepository taskOrganizeRepository; private final TaskOrganizeMapper taskOrganizeMapper; private final RoleService roleService; - private final UserMessageService userMessageService; private final ExtensionNumberService extensionNumberService; private final CompanyRepository companyRepository; private final LabelOrganizeService labelOrganizeService; @@ -67,8 +67,6 @@ public class OrganizeServiceImpl implements OrganizeService { private final TaskUserDistributionRepository taskUserDistributionRepository; private final ExtensionUserRepository extensionUserRepository; - private final MessageNotificationRepository messageNotificationRepository; - /** * 新增小组 */ @@ -156,7 +154,7 @@ public class OrganizeServiceImpl implements OrganizeService { } /** - * 删除组,(过继组的信息)TODO:2.0版本开发 + * 删除组,(过继组的信息) TODO:2.0版本开发 */ @Override @Transactional(rollbackFor = Exception.class) @@ -171,7 +169,7 @@ public class OrganizeServiceImpl implements OrganizeService { sourceClueClient.updateOrganize(organizeId, replaceOrganizeId); } - /** + /** * 添加组员 */ @Override @@ -203,7 +201,7 @@ public class OrganizeServiceImpl implements OrganizeService { } /** - * 删除组员,(过继组员或者资源再分配)TODO:2.0版本开发 + * 删除组员,(过继组员或者资源再分配) TODO:2.0版本开发 */ @Override @Transactional(rollbackFor = Exception.class) @@ -253,7 +251,6 @@ public class OrganizeServiceImpl implements OrganizeService { @Override @Transactional(rollbackFor = Exception.class) public ResponseEntity saveOrganizeDistribution(OrganizeSaveDTO organizeSaveDTO) { - List userIdList = new ArrayList<>(); List organizeIdList = new ArrayList<>(); List weights = new ArrayList<>(); Long labelOrganizeId = organizeSaveDTO.getLabelOrganizeId(); @@ -335,19 +332,8 @@ public class OrganizeServiceImpl implements OrganizeService { taskOrganize.setRemark(organizeList.get(index).getRemark()); index++; taskOrganizeRepository.save(taskOrganize); - // 发送通知的用户id - OrganizeUser organizeUser = organizeUserRepository.findByOrganizeIdAndIsLeader(distributeResponseDTO.getDeptId(), true); - userIdList.add(organizeUser.getUserId()); } } - //发送通知 - MessageNotification messageNotification = new MessageNotification(); - messageNotification.setMessageTitle("分配通知"); - messageNotification.setMessageType(2); - messageNotification.setUserId(SecurityUtils.getCurrentUserId()); - messageNotification.setMessageContext("接收到" + organizeSaveDTO.getOrganizeTaskName() + "任务分配"); - MessageNotification notification = messageNotificationRepository.save(messageNotification); - userMessageService.createUserMessage(userIdList, notification, DefaultNumberConstants.TWO_NUMBER); return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK); } @@ -529,15 +515,6 @@ public class OrganizeServiceImpl implements OrganizeService { updateTaskOrganize.setOrganizeLabel(sourceLabe); } taskOrganizeRepository.save(updateTaskOrganize); - //发送通知 - List userIdList = new ArrayList<>(userIds); - MessageNotification messageNotification = new MessageNotification(); - messageNotification.setMessageTitle("分配通知"); - messageNotification.setMessageType(2); - messageNotification.setUserId(SecurityUtils.getCurrentUserId()); - messageNotification.setMessageContext("接收到" + updateTaskOrganize.getOrganizeTaskName() + "任务分配"); - MessageNotification notification = messageNotificationRepository.save(messageNotification); - userMessageService.createUserMessage(userIdList, notification, DefaultNumberConstants.TWO_NUMBER); return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.SUCCESS), HttpStatus.OK); } @@ -736,6 +713,118 @@ public class OrganizeServiceImpl implements OrganizeService { return new ResponseEntity<>(null, HttpStatus.OK); } + @Override + @Transactional(rollbackFor = Exception.class) + public void convert(OrganizeConvertDTO organizeConvertDTO) { + Long userId = organizeConvertDTO.getUserId(); + Long replaceUserId = organizeConvertDTO.getReplaceUserId(); + Long organizeId = organizeConvertDTO.getOrganizeId(); + int roleLevel = organizeConvertDTO.getRoleLevel(); + if (userId.equals(replaceUserId)) throw new BadRequestException("替换人与被替换人不能相同,请重新选择"); + + User user = userRepository.findById(userId).orElseGet(User::new); + List userRoles = user.getRoles().stream().map(Role::getId).collect(Collectors.toList()); + + // 被替换人是组长 + if (userRoles.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) { + if (replaceUserId == null) throw new BadRequestException("被替换人为组长,请选择替换人"); + + User repUser = userRepository.findById(replaceUserId).orElseGet(User::new); + List repUserRoles = repUser.getRoles().stream().map(Role::getId).collect(Collectors.toList()); + + OrganizeUser repository = organizeUserRepository.findByUserId(replaceUserId); + //1、被替换人的组关系 全部改变 + List organizeUsers = organizeUserRepository.findByCreateByOrUserId(userId, userId); + for (OrganizeUser organizeUser : organizeUsers) { + if (organizeUser.getIsLeader()) organizeUser.setUserId(replaceUserId); + else organizeUser.setCreateBy(replaceUserId); + } + organizeUserRepository.saveAll(organizeUsers); + //2、替换人是组长 + if (repUserRoles.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) { + List list = organizeUserRepository.findByOrganizeId(organizeId); + for (OrganizeUser organizeUser : list) { + if (organizeUser.getIsLeader()) organizeUser.setUserId(userId); + else organizeUser.setCreateBy(userId); + } + organizeUserRepository.saveAll(list); + } else { + //3、替换人是组员 + userService.updateRole(replaceUserId, RoleNumberConstants.MINUS_NINE_NUMBER); + userService.updateRole(userId, RoleNumberConstants.MINUS_FIVE_NUMBER); + repository.setUserId(userId); + organizeUserRepository.save(repository); + } + } else { + //被替换人是组员 + if (replaceUserId != null) { + User repUser = userRepository.findById(replaceUserId).orElseGet(User::new); + List repUserRoles = repUser.getRoles().stream().map(Role::getId).collect(Collectors.toList()); + //1、替换人是组长 + if (repUserRoles.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) { + userService.updateRole(userId, RoleNumberConstants.MINUS_NINE_NUMBER); + userService.updateRole(replaceUserId, RoleNumberConstants.MINUS_FIVE_NUMBER); + OrganizeUser userOrganizeUser = organizeUserRepository.findByUserId(userId); + userOrganizeUser.setUserId(replaceUserId); + List list = organizeUserRepository.findByOrganizeId(organizeId); + for (OrganizeUser organizeUser : list) { + if (organizeUser.getIsLeader()) organizeUser.setUserId(userId); + else organizeUser.setCreateBy(userId); + } + list.add(userOrganizeUser); + organizeUserRepository.saveAll(list); + } else { + //2、替换人是组员 + List organizeUserList = organizeUserRepository.findByUserIdIn(ListUtil.of(userId, replaceUserId)); + OrganizeUser userOrganizeUser = organizeUserList.get(DefaultNumberConstants.ONE_NUMBER); + OrganizeUser repOrganizeUser = organizeUserList.get(DefaultNumberConstants.ZERO_NUMBER); + userOrganizeUser.setUserId(replaceUserId); + repOrganizeUser.setUserId(userId); + organizeUserRepository.saveAll(ListUtil.of(userOrganizeUser, repOrganizeUser)); + } + } else { + // 没有替换人 + if (roleLevel == 9) { + // 降级对面组长为组长角色 , 提升userId为组长,原来组不动 + userService.updateRole(userId, RoleNumberConstants.MINUS_NINE_NUMBER); + List list = organizeUserRepository.findByOrganizeId(organizeId); + Long leaderUserId = null; + for (OrganizeUser organizeUser : list) { + if (organizeUser.getIsLeader()){ + organizeUser.setIsLeader(false); + leaderUserId = organizeUser.getUserId(); + } + organizeUser.setCreateBy(userId); + } + userService.updateRole(leaderUserId, RoleNumberConstants.MINUS_FIVE_NUMBER); + OrganizeUser organizeUser = organizeUserRepository.findByUserId(userId); + organizeUser.setOrganizeId(organizeId); + organizeUser.setIsLeader(true); + organizeUser.setCreateBy(SecurityUtils.getCurrentUserId()); + list.add(organizeUser); + organizeUserRepository.saveAll(list); + } else { + // 修改userId去别的组 + OrganizeUser organizeUser = organizeUserRepository.findByUserId(userId); + organizeUser.setOrganizeId(organizeId); + OrganizeUser leader = organizeUserRepository.findByOrganizeIdAndIsLeader(organizeId, true); + organizeUser.setCreateBy(leader.getUserId()); + } + } + } + // 分机号变动 + extensionNumberService.extensionNumberConvert(userId, replaceUserId, organizeId); + // 资源所属组相互转换 + Map map = new HashMap<>(); + map.put(userId, organizeConvertDTO.getOrganizeId()); + if (replaceUserId != null) { + OrganizeUser organizeUser = organizeUserRepository.findByUserId(replaceUserId); + map.put(replaceUserId, organizeUser.getOrganizeId()); + } + ResponseEntity response = sourceClueClient.updateClueOrganize(map); + if (response.getStatusCode().value() != 200) throw new BadRequestException("修改失败"); + } + /** * 小组id查询组员用户信息 */ @@ -782,21 +871,6 @@ public class OrganizeServiceImpl implements OrganizeService { return hashSet; } - /** - * 封装返回用户id - */ - public List> packageUser(Set userIdList) { - List userList = userRepository.findAllById(userIdList); - List> arrayList = new ArrayList<>(); - for (User user : userList) { - Map map = new HashMap<>(); - map.put("id", user.getId()); - map.put("label", user.getNickName()); - arrayList.add(map); - } - return arrayList; - } - /** * 查询组成员列表用户信息 */ diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskServiceImpl.java index 5c0566fa..e94dfff3 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/TaskServiceImpl.java @@ -53,7 +53,7 @@ public class TaskServiceImpl implements TaskService { private final TaskRepository taskRepository; private final TaskMapper taskMapper; - private final OrganizeUserRepository organizeUserRepository; + private final OrganizeRepository organizeRepository; private final UserRepository userRepository; private final TaskOrganizeRepository taskOrganizeRepository; private final SourceClueClient sourceClueClient; @@ -271,8 +271,8 @@ public class TaskServiceImpl implements TaskService { } for (TaskDto taskDto : taskDtoMap) { - //任务下的小组信息查询 - selectOrganizeUser(taskDto); + // 任务关联的小组信息 + this.selectOrganizeUser(taskDto); //插入标签信息 List labels = labelService.findAccordLabel(taskDto.getLabelOrganizeId(), collect); taskDto.setTotalNumber(taskDto.getTotalNumber() == null ? DefaultNumberConstants.ZERO_NUMBER : taskDto.getTotalNumber()); @@ -409,16 +409,17 @@ public class TaskServiceImpl implements TaskService { } @Override - public void sendErrMessage(String errorMessage, Long userId) { + public void sendMessage(String message, Long userId, String type) { Map map = new HashMap<>(); - map.put("message", errorMessage); + map.put("message", message); map.put("code", 500); - map.put("type", "source_error"); + if (type.equals("create")) map.put("code", 200); + map.put("type", type); JSONObject jsonData = new JSONObject(); jsonData.putOpt("data", map); - String message = JSONUtil.toJsonStr(jsonData); - webSocketServer.sendMessage(message, userId); + String messageJSON = JSONUtil.toJsonStr(jsonData); + webSocketServer.sendMessage(messageJSON, userId); } @Override @@ -444,16 +445,23 @@ public class TaskServiceImpl implements TaskService { //任务下的小组信息返回 List taskOrganizeList = taskOrganizeRepository.findByTaskId(taskDto.getId()); + List organizeIdList = taskOrganizeList.stream().map(TaskOrganize::getOrganizeId).collect(Collectors.toList()); + List organizeList = organizeRepository.findByIdIn(organizeIdList); + Map> map = organizeList.stream().collect(Collectors.groupingBy(Organize::getId)); if (CollUtil.isNotEmpty(taskOrganizeList)) { for (TaskOrganize taskOrganize : taskOrganizeList) { - List userIdList = organizeUserRepository.findByOrganizeId(taskOrganize.getOrganizeId()); - for (OrganizeUser userIds : userIdList) { - //判断是否为组长 - if (userIds.getIsLeader()) { - User user = userRepository.findById(userIds.getUserId()).orElseGet(User::new); - taskOrganize.setUserNickName(user.getNickName()); - } + if (map.containsKey(taskOrganize.getOrganizeId())){ + List organizes = map.get(taskOrganize.getOrganizeId()); + taskOrganize.setOrganizeName(organizes.get(0).getOrganizeName()); } +// List userIdList = organizeUserRepository.findByOrganizeId(taskOrganize.getOrganizeId()); +// for (OrganizeUser userIds : userIdList) { +// //判断是否为组长 +// if (userIds.getIsLeader()) { +// User user = userRepository.findById(userIds.getUserId()).orElseGet(User::new); +// taskOrganize.setUserNickName(user.getNickName()); +// } +// } } taskDto.setTaskOrganizeList(taskOrganizeList); } else { diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java index 7eb2ede2..e938d552 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/UserService.java @@ -50,32 +50,21 @@ public interface UserService { /** * 新增用户 - * - * @param resources / - * @return / */ User create(User resources); /** * 编辑用户 - * - * @param resources / - * @throws Exception */ void update(User resources) throws Exception; /** * 删除用户 - * - * @param delUserDTO / */ void delete(DelUserDTO delUserDTO); /** * 根据用户名查询 - * - * @param userName / - * @return / */ UserDto findByName(String userName); @@ -126,82 +115,51 @@ public interface UserService { * 导出数据 * * @param queryAll 待导出的数据 - * @param response / - * @throws IOException / */ void download(List queryAll, HttpServletResponse response) throws IOException; /** * 用户自助修改资料 - * - * @param resources / */ void updateCenter(User resources); /** * 查询管理员 - * - * @param roleIds - * @return */ List findByManager(List roleIds); /** * 查询所有启用id - * - * @return */ List queryAllUserIds(); /** * 管理员查询所有列表 - * - * @param managerId - * @return */ List queryUserIdsByManager(Long managerId); /** * 角色查询用户 - * - * @param roleId - * @return */ List queryRoleUser(Long roleId); /** * 创建用户 - * - * @param file - * @param companyId - * @param userDto - * @return - * @throws IOException */ void fileCreateUser(List file, Long companyId, UserDto userDto); /** * 查询用户树状图 - * - * @param criteria - * @param pageable - * @return */ Map queryUserTree(UserQueryCriteria criteria, Pageable pageable); /** * 公司id修改账户状态 - * - * @param flag - * @param ids */ void updateUserStatusByCompanyId(Boolean flag, List ids); /** * 公司删除用户 - * - * @param companyId - * @return */ void deleteCompany(Long companyId); @@ -214,81 +172,63 @@ public interface UserService { /** * 批量开通用户过期时间 - * - * @param orderDtoList */ void updateUserExpirationTime(List orderDtoList); /** * 过期时间查找 - * - * @param date - * @param flag - * @return */ List findUserByExpirationTime(DateTime date, Boolean flag); /** * 获取指定用户名 - * - * @param userIds - * @return */ Map queryName(Set userIds); /** * 获取指定用户昵称 - * - * @param userIds - * @return */ Map queryNickName(Set userIds); /** * 查询用户信息 - * - * @param userId - * @return */ UserDto findUserInfo(Long userId); /** * 获取指定用户是否开启审核资源文件权限 - * - * @param userId - * @return */ Boolean findIsReview(Long userId); /** * 购买套餐 - * - * @param buyComboDTO 请求参数 */ void buyPackage(BuyComboDTO buyComboDTO); /** * 修改用户过期时间 - * - * @param userId - * @param newDate */ void updateUserExpirationTimeByUserId(Date newDate, Long userId); /** - *用户查询过期时间 - * @param currentUserId - * @return + * 用户查询过期时间 */ Date findExpirationTimeByUserId(Long currentUserId); /** * 清除用户缓存 - * @param currentUserId */ - void removeUserExpiration(Long currentUserId); + void removeUserExpiration(Long currentUserId); + + /** + * 修改用户角色 + * + * @param userId 用户ID + * @param roleType 角色ID + */ + void updateRole(Long userId, Long roleType); /** * 工号查找用户 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 06475173..71f09b76 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 @@ -164,6 +164,7 @@ public class UserServiceImpl implements UserService { copyUser.setWhichUserId(userDto.getId()); copyUser.setCompanyId(companyId); copyUser.setEnabled(Boolean.FALSE); + copyUser.setTurnCrmNum(50); userRepository.save(copyUser); } } @@ -482,6 +483,8 @@ public class UserServiceImpl implements UserService { redisUtils.del(CacheKey.DATA_USER + resources.getId()); redisUtils.del(CacheKey.MENU_USER + resources.getId()); redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); + // 踢出用户 + this.remoteAuthService.delete(Collections.singleton(user.getId())); } // 如果用户被禁用,则清除用户登录信息 if (Boolean.FALSE.equals(resources.getEnabled())) { @@ -621,7 +624,6 @@ public class UserServiceImpl implements UserService { throw new BadRequestException("删除失败"); // 踢出用户 this.remoteAuthService.delete(Sets.newHashSet(userIds)); - //TODO 删除逻辑待补充? //11、删除分机号 extensionNumberService.deleteExtensionNumberByCompany(user.getCompanyId()); //12、删除统计信息 @@ -633,11 +635,14 @@ public class UserServiceImpl implements UserService { return; } else if (roleIds.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) { // 二: 删除或者替换组长 - if (replaceUserId == null) throw new BadRequestException("请选择替换组长"); - if (CollUtil.isNotEmpty(replaceRoleIds) && !replaceRoleIds.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) - throw new BadRequestException("请选择组长角色的用户"); - organizeUserRepository.updateUser(userId, replaceUserId); - organizeUserRepository.updateCreateBy(replaceUserId, userId); + OrganizeUser organizeUser = organizeUserRepository.findByUserId(userId); + if (organizeUser.getId() != null) { + if (replaceUserId == null) throw new BadRequestException("请选择替换组长"); + if (CollUtil.isNotEmpty(replaceRoleIds) && !replaceRoleIds.contains(RoleNumberConstants.MINUS_NINE_NUMBER)) + throw new BadRequestException("请选择组长角色的用户"); + organizeUserRepository.updateUser(userId, replaceUserId); + organizeUserRepository.updateCreateBy(replaceUserId, userId); + } this.sourceDel(userId, replaceUserId); } else if (roleIds.contains(RoleNumberConstants.MINUS_FIVE_NUMBER)) { // 三: 删除或者替换业务员 @@ -875,4 +880,24 @@ public class UserServiceImpl implements UserService { return (long) DefaultNumberConstants.ZERO_NUMBER; } + @Override + @Transactional(rollbackFor = Exception.class) + public void updateRole(Long userId, Long roleType) { + User user = userRepository.findById(userId).orElseGet(User::new); + Set list = new HashSet<>(); + Role role = new Role(); + role.setId(roleType); + list.add(role); + user.setRoles(list); + userRepository.save(user); + + redisUtils.del(CacheKey.DATA_USER + userId); + redisUtils.del(CacheKey.MENU_USER + userId); + redisUtils.del(CacheKey.ROLE_AUTH + userId); + redisUtils.del(CacheKey.USER_DETAILS + "::" + user.getUsername()); + delCaches(user.getId(), user.getUsername()); + // 踢出用户 + this.remoteAuthService.delete(Collections.singleton(userId)); + } + } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionUserRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionUserRepository.java index a2825cd2..c6c2fae0 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionUserRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/dao/ExtensionUserRepository.java @@ -55,4 +55,6 @@ public interface ExtensionUserRepository extends JpaRepository headMap = new HashMap<>(); + headMap.put("'Connection'", "keep-alive"); + headMap.put("Host", "creator.xiaohongshu.com"); + headMap.put("sec-ch-ua", "\"Chromium\";v=\"110\", \"Not A(Brand\";v=\"24\", \"Microsoft Edge\";v=\"110\""); + headMap.put("X-t", "1677047663676"); + headMap.put("x-b3-traceid", "87449146ff4fd8ef"); + headMap.put("sec-ch-ua-mobile", "?0"); + headMap.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50"); + headMap.put("Accept", "application/json, text/plain, */*"); + headMap.put("X-s", "OYMiZgaUZgTC1gd612wk1iqJZBv+0Yw6OBc+slwJ0g13"); + headMap.put("sec-ch-ua-platform", "\"Windows\""); + headMap.put("Sec-Fetch-Site", "same-origin"); + headMap.put("Sec-Fetch-Mode", "cors"); + headMap.put("Sec-Fetch-Dest", "empty"); + headMap.put("Referer", "https://creator.xiaohongshu.com/creator/home"); + headMap.put("Accept-Encoding", "gzip, deflate, br"); + headMap.put("Accept-Language", "zh-CN,zh;q=0.9"); + headMap.put("Cookie", cid); + return HttpRequest.get(requestUrl).timeout(10_0000).headerMap(headMap, true).execute().body(); + } + + @GetMapping("/xhsApi") + @Inner(value = false) + public String xhsApi(@RequestParam("cid") String cid) { + String requestUrl = "https://edith.xiaohongshu.com/api/sns/web/v1/user/me"; + Map map = new HashMap<>(); + map.put("'Connection'", "keep-alive"); + map.put("Host", "edith.xiaohongshu.com"); + map.put("sec-ch-ua", "\"Chromium\";v=\"110\", \"Not A(Brand\";v=\"24\", \"Microsoft Edge\";v=\"110\""); + map.put("X-t", "1677822769165"); + map.put("x-b3-traceid", "28a8d74d397d64b7"); + map.put("sec-ch-ua-mobile", "?0"); + map.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50"); + map.put("Accept", "application/json, text/plain, */*"); + map.put("X-s", "16FCZjMlOls+0jMi1lVU0j9WsBAisBdU1gaUO6ZU0YF3"); + map.put("sec-ch-ua-platform", "\"Windows\""); + map.put("Sec-Fetch-Site", "same-site"); + map.put("Sec-Fetch-Mode", "cors"); + map.put("Sec-Fetch-Dest", "empty"); + map.put("Referer", "https://www.xiaohongshu.com/"); + map.put("Accept-Encoding", "gzip, deflate, br"); + map.put("Accept-Language", "zh-CN,zh;q=0.9"); + map.put("Cookie", cid); + return HttpRequest.get(requestUrl).timeout(10_0000).headerMap(map, true).execute().body(); + } +} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/TaskClient.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/TaskClient.java index 34888067..c9fd954e 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/TaskClient.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/TaskClient.java @@ -34,8 +34,8 @@ public interface TaskClient { ResponseEntity> queryTaskId(@RequestBody TaskQueryCriteria taskQueryCriteria); @ApiOperation("websocket发送错误信息") - @GetMapping(PAY_PREFIX + "/sendErrMessage") - void sendErrMessage(@RequestParam("errorMessage") String errorMessage, @RequestParam("userId") Long userId); + @GetMapping(PAY_PREFIX + "/sendMessage") + void sendMessage(@RequestParam("message") String message, @RequestParam("userId") Long userId, @RequestParam("type") String type); @ApiOperation("查询任务详情") @GetMapping(PAY_PREFIX + "/queryDetails") diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/fallback/TaskClientFallback.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/fallback/TaskClientFallback.java index e509e01a..5e5dadc1 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/fallback/TaskClientFallback.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/feign/fallback/TaskClientFallback.java @@ -33,7 +33,7 @@ public class TaskClientFallback implements TaskClient { } @Override - public void sendErrMessage(String errorMessage, Long userId) { + public void sendMessage(String message, Long userId, String type) { } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java index ec008c49..4e95a74b 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ClueController.java @@ -13,15 +13,11 @@ import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; -import org.springframework.http.HttpRequest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.http.server.ServerHttpRequest; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; import java.util.Set; @@ -122,6 +118,13 @@ public class ClueController { return new ResponseEntity<>(clueService.judgeMember(judgeMemberId), HttpStatus.OK); } + @ApiOperation("删除人上传资源") + @DeleteMapping("/delIndividualClue") + public CommonResponse delIndividualClue(@RequestBody Long clueId) { + clueService.delIndividualClue(clueId); + return CommonResponse.createBySuccess(); + } + @ApiOperation("删除所有关联数据") @PostMapping("/delClueAll") public ResponseEntity delClueAll(@RequestBody Set taskIds) { @@ -193,4 +196,10 @@ public class ClueController { public CommonResponse> countClueByMemberStatus(@RequestBody ClueQueryCriteria clueQueryCriteria) { return CommonResponse.createBySuccess(clueService.countClueByMemberStatus(clueQueryCriteria)); } + + @ApiOperation("根据组员修改所属组") + @PostMapping("/updateClueOrganize") + public ResponseEntity updateClueOrganize(@RequestBody Map map) { + return new ResponseEntity<>(clueService.updateClueOrganize(map), HttpStatus.OK); + } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java index b3805853..86a14666 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueJpa.java @@ -125,15 +125,16 @@ public class ClueJpa { Boolean isAdmin = clueQueryCriteria.getIsAdmin(); Integer publicPoolStatus = clueQueryCriteria.getPublicPoolStatus(); Long userId = clueQueryCriteria.getUserId(); + String nid = clueQueryCriteria.getNid(); List newestCallTimeList = clueQueryCriteria.getNewestCallTime(); List createTime = clueQueryCriteria.getCreateTime(); -// if (clueQueryCriteria.getTaskIds() == null && clueQueryCriteria.getTaskName() != null) { -// return entityManager.createNativeQuery(sql.toString()).getResultList(); -// } if (id != null) { sql.append("and c.id = :id "); } + if (nid != null){ + sql.append("and c.nid = :nid "); + } if (StringUtils.isNotBlank(name)) { sql.append("and c.name like :name "); } @@ -201,6 +202,9 @@ public class ClueJpa { if (id != null) { query.setParameter("id", id); } + if (nid != null){ + query.setParameter("nid", AESUtils.encrypt(nid, secret)); + } if (StringUtils.isNotBlank(name)) { query.setParameter("name", "%" + name + "%"); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java index 8366798e..ada61e7c 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java @@ -149,4 +149,17 @@ public interface ClueMiddleRepository extends JpaRepository, J @Query(value = " select * from tb_clue_middle where (clue_stage_time between ?2 and ?3) and task_id in ?1 and (coalesce (?4,null) is null or clue_stage =?4)", nativeQuery = true) List reportClueByTaskIdAndStage(List taskId, String beginTime, String endTime, Integer stages); + /** + * 组员用户ID查询(返回一条) + */ + @Query(value = "SELECT * FROM `tb_clue_middle` where member_id = ?1 and organize_id is not null", nativeQuery = true) + ClueMiddle findByMemberIdOne(Long memberId); + + /** + * 更新资源所属组 + */ + @Modifying + @Query(value = " update tb_clue_middle set organize_id = ?2 where member_id = ?1 and organize_id is not null", nativeQuery = true) + void updateOrganizeIdByMemberId(Long memberId, Long organizeId); + } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueRecordRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueRecordRepository.java index e4f2505a..ba2c9683 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueRecordRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueRecordRepository.java @@ -15,21 +15,16 @@ public interface ClueRecordRepository extends JpaRepository, J /** * 任务id查询 - * @param taskId - * @return */ List findByTaskId(Long taskId); /** * 任务id与审核状态查询 - * @param taskId - * @return */ List findByTaskIdAndIsPass(Long taskId, Integer isPass); /** * 删除所有任务相关 - * @param taskIds */ void deleteByTaskIdIn(Set taskIds); @@ -39,14 +34,27 @@ public interface ClueRecordRepository extends JpaRepository, J /** * 任务id更新审核状态 - * @param taskIds - * @param isPass */ @Modifying @Query(value = " update tb_clue_record set is_pass = ?2 where task_id in ?1 ", nativeQuery = true) void updateIsPassByTaskIdIn(Set taskIds, Integer isPass); - List findByIsPassAndCreateByIn(Integer isPass,Set createByList); + List findByIsPassAndCreateByIn(Integer isPass, Set createByList); List findByTaskIdIn(Set taskIdList); + + /** + * ID批量查询 + */ + List findByIdIn(List ids); + + /** + * 修改文件上传状态 + * + * @param recordIds 记录ID + * @param status 状态 + */ + @Modifying + @Query(value = " update tb_clue_record set status = ?2 where id in ?1 ", nativeQuery = true) + void updateStatus(List recordIds, int status); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ConductRecordRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ConductRecordRepository.java index 72a08ed9..a99ae3a1 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ConductRecordRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ConductRecordRepository.java @@ -31,4 +31,6 @@ public interface ConductRecordRepository extends JpaRepository findByClueIdInOrderByCreateTimeDesc(Set clueIdList); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueRecord.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueRecord.java index 3539a103..905666bf 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueRecord.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ClueRecord.java @@ -37,9 +37,9 @@ public class ClueRecord implements Serializable { @JsonSerialize(using = ToStringSerializer.class) private Long id; - @ApiModelProperty(value = "上传状态 0:上传成功 1:上传失败 (默认0)") + @ApiModelProperty(value = "上传状态 0:上传中 1:上传失败 2:上传成功") @Column(name = "status") - private Boolean status; + private Integer status; @ApiModelProperty(value = "上传类型 0:自定义模板 1:UC 2:快手 3:抖音 4:百度 5:动态任务自定义模板 6:拓客任务模板") @Column(name = "upload_type") diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/DynamicTaskListener.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/DynamicTaskListener.java index 673d771e..88d39046 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/DynamicTaskListener.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/DynamicTaskListener.java @@ -1,5 +1,6 @@ package com.baiye.module.listener; +import cn.hutool.core.collection.CollUtil; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.baiye.constant.DefaultNumberConstants; @@ -28,15 +29,13 @@ public class DynamicTaskListener extends AnalysisEventListener 0) { + if (CollUtil.isNotEmpty(clues)) { clueService.saveClue(clues, baseExcelListenerDto.getTaskId(), DefaultNumberConstants.ZERO_NUMBER); } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/TokerListener.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/TokerListener.java index 71605d43..43918a2a 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/TokerListener.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/TokerListener.java @@ -31,15 +31,13 @@ public class TokerListener extends AnalysisEventListener { private static ClueService clueService; public TokerListener(ClueService clueService, BaseExcelListenerDto baseExcelListenerDto) { + log.info("==============开始导入拓客动态任务表单:{}", Thread.currentThread().getName()); this.clueService = clueService; this.baseExcelListenerDto = baseExcelListenerDto; } /** * 每条数据都会回调此函数,1000条处理一次 - * - * @param tokerListenerDto - * @param analysisContext */ @Override public void invoke(TokerListenerDto tokerListenerDto, AnalysisContext analysisContext) { @@ -52,12 +50,10 @@ public class TokerListener extends AnalysisEventListener { /** * 读取文件完成回调函数,清空集合剩余数据 - * - * @param analysisContext */ @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { - saveData(); + if (CollUtil.isNotEmpty(rows)) saveData(); rows.clear(); nidList.clear(); } @@ -76,7 +72,7 @@ public class TokerListener extends AnalysisEventListener { cluePackage(clues, nidList); nidList.clear(); } - }else { + } else { addClue(clues, nid, 0); } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/ZdyListener.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/ZdyListener.java index 100fd754..370ea5d2 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/ZdyListener.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/ZdyListener.java @@ -1,5 +1,6 @@ package com.baiye.module.listener; +import cn.hutool.core.collection.CollUtil; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.baiye.constant.DefaultNumberConstants; @@ -26,15 +27,13 @@ public class ZdyListener extends AnalysisEventListener { private static ClueService clueService; public ZdyListener(ClueService clueService, BaseExcelListenerDto baseExcelListenerDto) { + log.info("==============开始导入自定义表单:{}", Thread.currentThread().getName()); this.clueService = clueService; this.baseExcelListenerDto = baseExcelListenerDto; } /** * 每条数据都会回调此函数,1000条处理一次 - * - * @param zdyListenerDto - * @param analysisContext */ @Override public void invoke(ZdyListenerDto zdyListenerDto, AnalysisContext analysisContext) { @@ -47,12 +46,10 @@ public class ZdyListener extends AnalysisEventListener { /** * 读取文件完成回调函数,清空集合剩余数据 - * - * @param analysisContext */ @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { - saveData(); + if (CollUtil.isNotEmpty(rows)) saveData(); rows.clear(); } @@ -72,7 +69,7 @@ public class ZdyListener extends AnalysisEventListener { clues.add(clue); } } - if (clues.size() > 0) { + if (CollUtil.isNotEmpty(clues)) { clueService.saveClue(clues, baseExcelListenerDto.getTaskId(), DefaultNumberConstants.ZERO_NUMBER); } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/dto/BaseExcelListenerDto.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/dto/BaseExcelListenerDto.java index 39d64b83..c16ccb5c 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/dto/BaseExcelListenerDto.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/listener/dto/BaseExcelListenerDto.java @@ -1,11 +1,10 @@ package com.baiye.module.listener.dto; import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; -@Data +@Getter +@Setter @AllArgsConstructor @NoArgsConstructor public class BaseExcelListenerDto { @@ -24,4 +23,11 @@ public class BaseExcelListenerDto { @ApiModelProperty(value = "文件名") private String oneFileName; + + public BaseExcelListenerDto( Long userId, Integer origin, Long taskId, String oneFileName) { + this.userId = userId; + this.origin = origin; + this.taskId = taskId; + this.oneFileName = oneFileName; + } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java index 1e40b158..8bb141ff 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ClueService.java @@ -73,7 +73,8 @@ public interface ClueService { /** * 修改组员 - * @param userId 被替换人用户ID + * + * @param userId 被替换人用户ID * @param replaceUserId 替换人用户ID */ Boolean updateMember(Long userId, Long replaceUserId); @@ -103,6 +104,11 @@ public interface ClueService { */ void saveTask(BaseExcelListenerDto baseExcelListenerDto); + /** + * 删除人上传资源 + */ + void delIndividualClue(Long clueId); + /** * 删除所有关联数据 */ @@ -160,16 +166,18 @@ public interface ClueService { /** * 保存线索 - * @param tagList - * @param phoneList - * @param taskId - * @param userId - * @param num */ void saveClue(List tagList, List phoneList, Long taskId, Long userId, Integer num); /** * 任务是否开启自动分配,开启了就分配掉 */ - void dynamicTaskDistribution(Long taskId,Integer uploadType); + void dynamicTaskDistribution(Long taskId, Integer uploadType); + + /** + * 根据组员修改所属组 + * + * @param map key:用户ID value:用户要修改的组 + */ + Boolean updateClueOrganize(Map map); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueRecordDto.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueRecordDto.java index cc980181..7b71e500 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueRecordDto.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueRecordDto.java @@ -24,7 +24,7 @@ public class ClueRecordDto implements Serializable { @ApiModelProperty(value = "上传状态 0:上传成功 1:上传失败 (默认0)") @ExcelIgnore - private Boolean status; + private Integer status; @ApiModelProperty(value = "上传类型 0:自定义模板 1:UC 2:快手 3:抖音 4:百度") @ExcelProperty(value = "渠道", index = 2, converter = ExportOriginConverter.class) 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 b9c73d6f..73c7cdcf 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 @@ -1,6 +1,7 @@ package com.baiye.module.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; @@ -44,7 +45,6 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class ClueServiceImpl implements ClueService { - private final ClueRepository clueRepository; private final ClueRecordRepository clueRecordRepository; private final ClueMiddleRepository clueMiddleRepository; @@ -97,13 +97,13 @@ public class ClueServiceImpl implements ClueService { //更新成功条数 Map> clueGroup = clueList.stream().collect(Collectors.groupingBy(Clue::getRecordId)); List successClueRecord = clueRecordRepository.findAllById(clueGroup.keySet()); - successClueRecord.forEach(se -> se.setSuccessNum(clueGroup.get(se.getId()).size())); + successClueRecord.forEach(se -> se.setSuccessNum(se.getSuccessNum() + clueGroup.get(se.getId()).size())); clueRecordRepository.saveAll(successClueRecord); //更新失败条数 并插入失败的信息 if (CollUtil.isNotEmpty(failRecords)) { Map> failGroup = failRecords.stream().collect(Collectors.groupingBy(ClueFailRecord::getRecordId)); List failClueRecord = clueRecordRepository.findAllById(failGroup.keySet()); - failClueRecord.forEach(fd -> fd.setFailNum(failGroup.get(fd.getId()).size())); + failClueRecord.forEach(fd -> fd.setFailNum(fd.getFailNum() + failGroup.get(fd.getId()).size())); clueRecordRepository.saveAll(failClueRecord); clueFailRecordRepository.saveAll(failRecords); } @@ -229,14 +229,9 @@ public class ClueServiceImpl implements ClueService { //查询线索记录 Set clueIdList = clueDtoList.stream().map(ClueDto::getId).collect(Collectors.toSet()); - List conductRecords = conductRecordRepository.findByClueIdIn(clueIdList); - Map map = new HashMap<>(); - if (CollUtil.isNotEmpty(conductRecords)) { - List sortConductRecord = conductRecords.stream().sorted(Comparator.comparing(ConductRecord::getCreateTime)).collect(Collectors.toList()); - for (ConductRecord conductRecord : sortConductRecord) { - map.put(conductRecord.getClueId(), conductRecord.getRecordInfo()); - } - } + List conductRecords = conductRecordRepository.findByClueIdInOrderByCreateTimeDesc(clueIdList); + Map> map = conductRecords.stream().collect(Collectors.groupingBy(ConductRecord::getClueId)); + // 列表中查询标签信息 和 axb请求字段 for (ClueDto clueDto : clueDtoList) { String value = (String) redisUtils.get(KeyFieldConstants.TASK_NAME_KEY + clueDto.getTaskId()); @@ -249,7 +244,8 @@ public class ClueServiceImpl implements ClueService { } clueDto.setTaskName(value); if (CollUtil.isNotEmpty(map) && map.containsKey(clueDto.getId())) { - clueDto.setClueRecord(map.get(clueDto.getId())); + List recordList = map.get(clueDto.getId()); + clueDto.setClueRecord(recordList.get(0).getRecordInfo()); } } return PageUtil.toPage(clueDtoList, count); @@ -469,7 +465,7 @@ public class ClueServiceImpl implements ClueService { } if (taskNum == null || taskNum == 0) { try { - taskClient.sendErrMessage("导入资源合规条数0条,请检查文件重新导入", userId); + taskClient.sendMessage("导入资源合规条数0条,请检查文件重新导入", userId, "source_error"); } catch (Exception e) { throw new BadRequestException("发送websocket失败"); } @@ -492,6 +488,24 @@ public class ClueServiceImpl implements ClueService { if (response.getStatusCode().value() != 200) throw new BadRequestException("创建任务失败"); } + @Override + @Transactional(rollbackFor = Exception.class) + public void delIndividualClue(Long clueId) { + ClueMiddle clueMiddle = clueMiddleRepository.findById(clueId).orElseGet(ClueMiddle::new); + ClueTalk clueTalk = clueTalkRepository.findById(clueId).orElseGet(ClueTalk::new); + if (clueTalk.getClueId() != null && clueTalk.getClueType() != 2) throw new BadRequestException("无法删除非个人上传资源"); + if (clueMiddle.getClueId() != null && clueMiddle.getClueType() != 2) throw new BadRequestException("无法删除非个人上传资源"); + + Set clueIds = Collections.singleton(clueId); + ClueQueryCriteria clueQueryCriteria = new ClueQueryCriteria(); + clueQueryCriteria.setId(clueId); + List clueAll = clueJpa.getClueList(clueQueryCriteria, null); + this.delete(clueAll ,clueIds); + + if (clueTalk.getClueId() != null ) clueTalkRepository.deleteById(clueId); + if (clueMiddle.getClueId() != null) clueMiddleRepository.deleteById(clueId); + } + @Override @Transactional(rollbackFor = Exception.class) public Boolean delClueAll(Set taskIds) { @@ -883,22 +897,21 @@ public class ClueServiceImpl implements ClueService { @Override @Transactional(rollbackFor = Exception.class) public void dynamicTaskDistribution(Long taskId, Integer uploadType) { - List clueIds; - if (uploadType == 6) { - clueIds = clueTalkRepository.findByTaskIdAndMemberStatus(taskId, DefaultNumberConstants.ZERO_NUMBER); - } else { - clueIds = clueMiddleRepository.findByTaskIdAndMemberStatus(taskId, DefaultNumberConstants.ZERO_NUMBER); - } CommonResponse response = taskClient.findTaskDistribution(taskId); - if (response.getStatus() == DefaultNumberConstants.ZERO_NUMBER) { DynamicTaskDistributionDTO dynamicTaskDistributionDTO = response.getData(); // 开启了自动分配 if (dynamicTaskDistributionDTO.getIsOpen() == 1) { List dynamicTaskDistributionUserDTOS = dynamicTaskDistributionDTO.getDynamicTaskDistributionUserDTOS(); if (CollUtil.isNotEmpty(dynamicTaskDistributionUserDTOS)) { - DistributeDTO distributeDTO = new DistributeDTO(); + // 不同的类型去不同的表查询数据 + List clueIds; + if (uploadType == 6) + clueIds = clueTalkRepository.findByTaskIdAndMemberStatus(taskId, DefaultNumberConstants.ZERO_NUMBER); + else + clueIds = clueMiddleRepository.findByTaskIdAndMemberStatus(taskId, DefaultNumberConstants.ZERO_NUMBER); // 获取用户分配的资源 + DistributeDTO distributeDTO = new DistributeDTO(); List userIdList = new ArrayList<>(); List weights = new ArrayList<>(); for (DynamicTaskDistributionUserDTO dynamicTaskDistributionUserDTO : dynamicTaskDistributionUserDTOS) { @@ -907,13 +920,9 @@ public class ClueServiceImpl implements ClueService { } int num = dynamicTaskDistributionUserDTOS.stream().mapToInt(DynamicTaskDistributionUserDTO::getRatio).sum(); // 比率分配数据 - if (num == DefaultNumberConstants.ONE_HUNDRED) { - distributeDTO.setIsWeight(true); - } + if (num == DefaultNumberConstants.ONE_HUNDRED) distributeDTO.setIsWeight(true); // 平均分配数据 - if (num == DefaultNumberConstants.ZERO_NUMBER) { - distributeDTO.setIsWeight(false); - } + if (num == DefaultNumberConstants.ZERO_NUMBER) distributeDTO.setIsWeight(false); distributeDTO.setDeptIds(userIdList); distributeDTO.setWeights(weights); distributeDTO.setResourceList(clueIds); @@ -921,11 +930,10 @@ public class ClueServiceImpl implements ClueService { if (distributeResponse.getStatus() == DefaultNumberConstants.ZERO_NUMBER) { for (DistributeResponseDTO data : distributeResponse.getData()) { - if (uploadType == 6) { + if (uploadType == 6) clueTalkRepository.updateMemberIdByClueIdIn(data.getResponseList(), data.getDeptId()); - } else { + else clueMiddleRepository.updateMemberIdByClueIdIn(data.getResponseList(), data.getDeptId()); - } } } } @@ -933,6 +941,16 @@ public class ClueServiceImpl implements ClueService { } } + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean updateClueOrganize(Map map) { + // 内部调用 循环最多两次 可以在循环中进行更新操作 + for (Long key : map.keySet()) { + clueMiddleRepository.updateOrganizeIdByMemberId(key, map.get(key)); + } + return true; + } + private HashMap getReportMap(List clueMiddles) { int newClue = 0; int communicat = 0; @@ -1007,6 +1025,12 @@ public class ClueServiceImpl implements ClueService { Long count = this.findClueCount(clueQueryCriteria); Set memberIds = clueList.stream().map(ClueDto::getMemberId).collect(Collectors.toSet()); Map userNickNameMap = userClient.findById(memberIds); + + //查询线索记录 + Set clueIdList = clueList.stream().map(ClueDto::getId).collect(Collectors.toSet()); + List conductRecords = conductRecordRepository.findByClueIdInOrderByCreateTimeDesc(clueIdList); + Map> map = conductRecords.stream().collect(Collectors.groupingBy(ConductRecord::getClueId)); + for (ClueDto clue : clueList) { //获取缓存中任务名称 clue.setTaskName(findTaskName(clue.getTaskId())); @@ -1015,6 +1039,11 @@ public class ClueServiceImpl implements ClueService { if (memberId != null && userNickNameMap.containsKey(memberId)) { clue.setDistributeUserName(userNickNameMap.get(memberId)); } + + if (CollUtil.isNotEmpty(map) && map.containsKey(clue.getId())) { + List recordList = map.get(clue.getId()); + clue.setClueRecord(recordList.get(0).getRecordInfo()); + } } return PageUtil.toPage(clueList, count); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/PublicCluePoolServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/PublicCluePoolServiceImpl.java index be77a836..780646ba 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/PublicCluePoolServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/PublicCluePoolServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import com.baiye.exception.BadRequestException; import com.baiye.feign.UserClient; +import com.baiye.model.dto.ClueDto; import com.baiye.model.dto.PublicCluePoolDto; import com.baiye.model.dto.PublicCluePoolQueryCriteria; import com.baiye.model.dto.UserDto; @@ -18,10 +19,8 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; +import java.util.stream.Collectors; /** * @author wjt @@ -42,6 +41,23 @@ public class PublicCluePoolServiceImpl implements PublicCluePoolService { public Map queryPublicCluePool(PublicCluePoolQueryCriteria publicCluePoolQueryCriteria, Pageable pageable) { List cluePoolList = clueJpa.getCluePoolList(publicCluePoolQueryCriteria, pageable); + + Set clueIds = cluePoolList.stream().map(PublicCluePoolDto::getClueId).collect(Collectors.toSet()); + List conductRecords = conductRecordRepository.findByClueIdInOrderByCreateTimeDesc(clueIds); + Map> map = conductRecords.stream().collect(Collectors.groupingBy(ConductRecord::getClueId)); + + for (PublicCluePoolDto publicCluePoolDto : cluePoolList) { + if (CollUtil.isNotEmpty(map) && map.containsKey(publicCluePoolDto.getClueId())) { + List conductRecordList = map.get(publicCluePoolDto.getClueId()); + if (conductRecordList.size() >= 2){ + //List records = conductRecordList.stream().sorted(Comparator.comparing(ConductRecord::getCreateTime)).collect(Collectors.toList()); + ConductRecord conductRecord = conductRecordList.get(1); + publicCluePoolDto.setClueRecord(conductRecord.getRecordInfo()); + } + if (conductRecordList.size() == 1) publicCluePoolDto.setClueRecord(conductRecordList.get(0).getRecordInfo()); + } + } + Long poolCount = clueJpa.getPoolCount(publicCluePoolQueryCriteria); return PageUtil.toPage(cluePoolList, poolCount); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/UploadFileServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/UploadFileServiceImpl.java index a1ec1ded..01339b34 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/UploadFileServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/UploadFileServiceImpl.java @@ -11,6 +11,7 @@ import com.baiye.module.entity.ClueRecord; import com.baiye.module.service.UploadFileService; import com.baiye.task.FileAnalysisTask; import com.baiye.util.TestingUtil; +import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -20,32 +21,29 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.Resource; import java.io.*; import java.text.SimpleDateFormat; import java.util.*; @Service @Slf4j +@RequiredArgsConstructor public class UploadFileServiceImpl implements UploadFileService { - @Resource - private FileAnalysisTask fileAnalysisTask; - @Resource - private ClueRecordRepository clueRecordRepository; - @Resource - private UserClient userClient; + private final FileAnalysisTask fileAnalysisTask; + + private final ClueRecordRepository clueRecordRepository; + + private final UserClient userClient; @Value(value = "${storage.url}") private String URL; + @Value(value = "${storage.auditingUrl}") private String auditingUrl; + @Value(value = "${storage.de_symbol}") private String DE_SYMBOL; - @Value("${snowflake.workerId}") - private int workerId; - @Value("${snowflake.datacenterId}") - private int datacenterId; private static final SimpleDateFormat timeTwo = new SimpleDateFormat("yyyy-MM-dd"); @@ -65,7 +63,7 @@ public class UploadFileServiceImpl implements UploadFileService { isCreateTask = true; } // 如果taskId是null就是小组任务,动态任务都需要传taskId - if (taskId == null) taskId = IdUtil.getSnowflake(workerId, datacenterId).nextId(); + if (taskId == null) taskId = IdUtil.getSnowflake(DefaultNumberConstants.NINE_NUMBER, DefaultNumberConstants.NINE_NUMBER).nextId(); // 文件是否需要审核,需要审核的不入库 Boolean flag = userClient.findIsReview(userId); //处理文件数据 @@ -120,15 +118,17 @@ public class UploadFileServiceImpl implements UploadFileService { */ @Transactional(rollbackFor = Exception.class) public ClueRecord saveClueRecord(String originalFilename, String newFileUrl, Integer uploadType, Long userId, Long taskId, Boolean flag) { - long clueRecordId = IdUtil.getSnowflake(workerId, datacenterId).nextId(); + long clueRecordId = IdUtil.getSnowflake(DefaultNumberConstants.NINE_NUMBER, DefaultNumberConstants.NINE_NUMBER).nextId(); ClueRecord clueRecord = new ClueRecord(); clueRecord.setId(clueRecordId); clueRecord.setOldFile(originalFilename); clueRecord.setNewFileUrl(newFileUrl); - clueRecord.setStatus(true); clueRecord.setUploadType(uploadType); clueRecord.setCreateBy(userId); clueRecord.setTaskId(taskId); + clueRecord.setStatus(DefaultNumberConstants.ZERO_NUMBER); + clueRecord.setSuccessNum(DefaultNumberConstants.ZERO_NUMBER); + clueRecord.setFailNum(DefaultNumberConstants.ZERO_NUMBER); int isPass = 0; if (flag) isPass = 1; clueRecord.setIsPass(isPass); diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/FileAnalysisTask.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/FileAnalysisTask.java index 5c5466ec..ecfabb32 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/FileAnalysisTask.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/FileAnalysisTask.java @@ -2,11 +2,9 @@ package com.baiye.task; import cn.hutool.core.collection.CollUtil; import com.alibaba.excel.EasyExcelFactory; -import com.baiye.constant.SecurityConstants; +import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.FileConstant; -import com.baiye.exception.BadRequestException; import com.baiye.feign.TaskClient; -import com.baiye.constant.FileConstant; import com.baiye.module.dao.*; import com.baiye.module.entity.ClueRecord; import com.baiye.module.entity.Task; @@ -22,14 +20,12 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.io.FileInputStream; -import java.util.*; import java.util.List; - +import java.util.stream.Collectors; @Component @Slf4j @@ -37,12 +33,16 @@ public class FileAnalysisTask { @Resource private ClueService clueService; + @Resource private TaskClient taskClient; + @Resource private ClueMiddleRepository clueMiddleRepository; + @Resource private ClueRecordRepository clueRecordRepository; + @Resource private ClueTalkRepository clueTalkRepository; @@ -57,39 +57,31 @@ public class FileAnalysisTask { @Async(value = "SendBigDataTaskExecutor") public void runFileAnalysisTask(List clueRecords, String oneFileName, Boolean isCreateTask) { if (CollUtil.isNotEmpty(clueRecords)) { + List recordIds = clueRecords.stream().map(ClueRecord::getId).collect(Collectors.toList()); try { for (ClueRecord clueRecord : clueRecords) { - BaseExcelListenerDto baseExcelListenerDto = new BaseExcelListenerDto(); - baseExcelListenerDto.setUserId(clueRecord.getCreateBy()); - baseExcelListenerDto.setClueRecordId(clueRecord.getId()); - baseExcelListenerDto.setOrigin(clueRecord.getUploadType()); - baseExcelListenerDto.setTaskId(clueRecord.getTaskId()); - baseExcelListenerDto.setOneFileName(oneFileName); + BaseExcelListenerDto baseExcelListenerDto = new BaseExcelListenerDto(clueRecord.getId(), clueRecord.getCreateBy(), + clueRecord.getUploadType(), clueRecord.getTaskId(), oneFileName); FileInputStream file = new FileInputStream(clueRecord.getNewFileUrl()); switch (clueRecord.getUploadType()) { case FileConstant.ZERO_NUMBER: - log.info("==============开始导入自定义表单============{}", Thread.currentThread().getName()); EasyExcelFactory.read(file, ZdyListenerDto.class, new ZdyListener(clueService, baseExcelListenerDto)).build().readAll(); break; case FileConstant.FIVE_NUMBER: - log.info("==============开始导入动态任务表单============{}", Thread.currentThread().getName()); EasyExcelFactory.read(file, DynamicTaskListenerDto.class, new DynamicTaskListener(clueService, baseExcelListenerDto)).build().readAll(); break; case FileConstant.SIX_NUMBER: - log.info("==============开始导入拓客动态任务表单============{}", Thread.currentThread().getName()); EasyExcelFactory.read(file, TokerListenerDto.class, new TokerListener(clueService, baseExcelListenerDto)).build().readAll(); break; - default: - break; } } + // 修改文件记录上传状态 + this.updateClueRecord(recordIds, DefaultNumberConstants.TWO_NUMBER); } catch (Exception e) { - taskClient.sendErrMessage("导入资源错误,请检查数据格式后重新导入", clueRecords.get(0).getCreateBy()); - //导入文件记录失败修改状态 - updateList(clueRecords); - e.printStackTrace(); - throw new BadRequestException("=========读取资源错误============"); + log.error("=========读取资源错误:,{}", e.getMessage()); + taskClient.sendMessage("导入资源错误,请检查数据格式后重新导入", clueRecords.get(0).getCreateBy(), "source_error"); + this.updateClueRecord(recordIds, DefaultNumberConstants.ONE_NUMBER); } //动态任务不需要创建任务,更新数据后return结束(注:拓客任务不指定任务ID也要新建任务) Integer uploadType = clueRecords.get(0).getUploadType(); @@ -102,33 +94,26 @@ public class FileAnalysisTask { task.setTotalNumber(taskNum); task.setIsDistribution(1); taskClient.updateTask(task); - // 查看此任务是否开启自动分配,开启了就分配掉 + // 任务自动分配(未开启就不分配) clueService.dynamicTaskDistribution(taskId, uploadType); + taskClient.sendMessage("上传成功", clueRecords.get(0).getCreateBy(), "create"); return; } //创建任务 Long taskId = clueRecords.get(0).getTaskId(); Long userId = clueRecords.get(0).getCreateBy(); if (taskId != null && userId != null && StringUtils.isNotBlank(oneFileName)) { - BaseExcelListenerDto baseExcelListenerDto = new BaseExcelListenerDto(); - baseExcelListenerDto.setUserId(userId); - baseExcelListenerDto.setTaskId(taskId); - baseExcelListenerDto.setOneFileName(oneFileName); - baseExcelListenerDto.setOrigin(uploadType); + BaseExcelListenerDto baseExcelListenerDto = new BaseExcelListenerDto(userId, uploadType, taskId, oneFileName); clueService.saveTask(baseExcelListenerDto); } + taskClient.sendMessage("上传成功", clueRecords.get(0).getCreateBy(), "create"); } } /** - * Propagation.REQUIRES_NEW: - * 1、会新开启事务,外层事务不会影响内部事务的提交/回滚 - * 2、内部事务的异常,会影响外部事务的回滚 + * 修改文件记录状态 */ - @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) - public void updateList(List clueRecords) { - //导入文件记录失败修改状态 - clueRecords.forEach(cs -> cs.setStatus(false)); - clueRecordRepository.saveAll(clueRecords); + public void updateClueRecord(List recordIds, int status) { + clueRecordRepository.updateStatus(recordIds, status); } }