diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java index 65fa7202..c97bf6d2 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/UserDto.java @@ -92,4 +92,6 @@ public class UserDto extends BaseDTO implements Serializable { private Long whichUserId; private Boolean isTokerAdmin = false; + + private Integer turnCrmNum; } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java index 4cc53070..1dbbb25a 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/Company.java @@ -132,6 +132,7 @@ public class Company extends BaseEntity implements Serializable { @Column(name = "dmp_delivery_fee") private Double dmpDeliveryFee; - - + @ApiModelProperty("子用户数量") + @Column(name = "son_user_num") + private Integer sonUserNum; } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/User.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/User.java index afbdd1e9..c6e4e24e 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/User.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/domain/User.java @@ -117,6 +117,11 @@ public class User extends BaseEntity implements Serializable { @ApiModelProperty(value = "是否审核") private Boolean isReview = Boolean.FALSE; + @Column(name = "turn_crm_num") + @NotNull(message = "转CRM数值不能为空",groups = Update.class) + @ApiModelProperty(value = "用户每天最大转crm条数") + private Integer turnCrmNum; + @Transient private Long templateId; diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java index ee5ff7d3..f19bfc54 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CompanyDto.java @@ -21,7 +21,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import javax.persistence.Column; import javax.validation.constraints.NotBlank; import java.io.Serializable; @@ -107,5 +106,6 @@ public class CompanyDto extends BaseDTO implements Serializable { @ApiModelProperty("拓客去显号价格") private Double talkCallFee; - + @ApiModelProperty("子用户数量") + private Integer sonUserNum; } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CreateUserDTO.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CreateUserDTO.java index 6eb06b19..17fc3263 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CreateUserDTO.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/dto/CreateUserDTO.java @@ -86,6 +86,10 @@ public class CreateUserDTO { @ApiModelProperty(value = "公司类型") private Integer companyType; + @NotNull(message = "转CRM数值不能为空") + @ApiModelProperty(value = "用户每天最大转crm条数") + private Integer turnCrmNum; + @Override public int hashCode() { return Objects.hash(id, username); diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java index d118873e..1abeb119 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/CompanyServiceImpl.java @@ -108,6 +108,7 @@ public class CompanyServiceImpl implements CompanyService { public CompanyDto createCompany(CompanyDto companyDto) { Company company = new Company(); BeanUtil.copyProperties(companyDto, company); + companyDto.setSonUserNum((int) DefaultNumberConstants.ONE_HUNDRED); return companyMapper.toDto(companyRepository.save(company)); } diff --git a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java index e07175fe..2ee4644b 100644 --- a/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java +++ b/manage/ad-platform-management/src/main/java/com/baiye/modules/system/service/impl/UserServiceImpl.java @@ -177,6 +177,13 @@ public class UserServiceImpl implements UserService { @Override @Transactional(rollbackFor = Exception.class) public void createUserOrFile(CreateUserDTO userDTO) { + if (userDTO.getCompanyId() != null){ + Integer sonUserNum = companyService.findCompanyInfo(userDTO.getCompanyId()).getSonUserNum(); + int size = userRepository.findByCompanyId(userDTO.getCompanyId()).size() - DefaultNumberConstants.ONE_NUMBER; + if (sonUserNum > size){ + throw new BadRequestException("子账号超过上限,请联系管理员"); + } + } Long companyId = null; User user = new User(); boolean flag = Boolean.FALSE; @@ -398,9 +405,8 @@ public class UserServiceImpl implements UserService { if (userRepository.findByPhone(resources.getPhone()) != null) { throw new EntityExistException(User.class, "phone", resources.getPhone()); } - User save = userRepository.save(resources); - return save; + return userRepository.save(resources); } @@ -464,6 +470,7 @@ public class UserServiceImpl implements UserService { user.setPhone(resources.getPhone()); user.setNickName(resources.getNickName()); user.setGender(resources.getGender()); + user.setTurnCrmNum(resources.getTurnCrmNum()); userRepository.save(user); // 清除缓存 delCaches(user.getId(), user.getUsername()); diff --git a/services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnCrmLogRepository.java b/services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnCrmLogRepository.java new file mode 100644 index 00000000..199c3f46 --- /dev/null +++ b/services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnCrmLogRepository.java @@ -0,0 +1,17 @@ +package com.baiye.module.dao; + +import com.baiye.module.entity.TurnCrmLog; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; + +public interface TurnCrmLogRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 查询此用户转crm总量 + * @param userId + * @return + */ + @Query(value = "select count(*) from tb_turn_crm_log where user_id = ?1", nativeQuery = true) + Integer findByUserIdCount(Long userId); +} diff --git a/services/ad-platform-source/src/main/java/com/baiye/module/entity/TurnCrmLog.java b/services/ad-platform-source/src/main/java/com/baiye/module/entity/TurnCrmLog.java new file mode 100644 index 00000000..d89099dc --- /dev/null +++ b/services/ad-platform-source/src/main/java/com/baiye/module/entity/TurnCrmLog.java @@ -0,0 +1,33 @@ +package com.baiye.module.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * TurnCrmLog + * + * @author yqy + * @date 2022-11-17 10:40:37 + */ +@Data +@Entity +@Table(name = "tb_turn_crm_log") +@ApiModel(value = "资源转crm日志表") +public class TurnCrmLog implements Serializable { + + private static final long serialVersionUID = 1271571231859316736L; + + @Id + @ApiModelProperty(value = "主键ID") + @Column(name = "clue_id") + @GeneratedValue(strategy = GenerationType.AUTO) + private Long clueId; + + @ApiModelProperty(value = "用户ID") + @Column(name = "user_id") + private Long userId; +} diff --git a/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java b/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java index f804dbb7..2ae2be2a 100644 --- a/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java +++ b/services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ClueServiceImpl.java @@ -67,6 +67,7 @@ public class ClueServiceImpl implements ClueService { private final OceanEngineClueIdRepository oceanEngineClueIdRepository; private final ClueFailRecordRepository clueFailRecordRepository; private final AssignDataClient assignDataClient; + private final TurnCrmLogRepository turnCrmLogRepository; private static SimpleDateFormat timeOne = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -786,7 +787,13 @@ public class ClueServiceImpl implements ClueService { } @Override + @Transactional(rollbackFor = Exception.class) public void clueBackFlow(Long taskId, Long clueId, Long userId, Integer clueType) { + Integer userCount = turnCrmLogRepository.findByUserIdCount(userId); + UserDto userInfo = userClient.findUserInfo(userId); + if (userCount != null && userCount > userInfo.getTurnCrmNum()){ + throw new BadRequestException("回流失败, 每天上限" + userInfo.getTurnCrmNum() +"条,请联系管理员"); + } // 初始化线索加密字段 Clue clue = clueRepository.findById(clueId).orElseGet(Clue::new); clue.setIsEncryption(DefaultNumberConstants.ZERO_NUMBER); @@ -829,6 +836,12 @@ public class ClueServiceImpl implements ClueService { task.setId(taskId); task.setTotalNumber(taskNum); taskClient.updateTask(task); + + // 记录转crm日志 + TurnCrmLog turnCrmLog = new TurnCrmLog(); + turnCrmLog.setClueId(clueId); + turnCrmLog.setUserId(userId); + turnCrmLogRepository.save(turnCrmLog); } @Override