From b4e18527e1ca2a51af57ef6613a4788fe2ef0613 Mon Sep 17 00:00:00 2001 From: yqy Date: Mon, 6 Feb 2023 09:53:30 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=B8=AA=E5=BE=AE=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/domain/ActivationRecord.java | 56 ++++++++ .../httpRequest/ActivationCodeRequestApi.java | 128 ++++++++++++++++++ .../repository/ActivationCodeRepository.java | 8 ++ .../repository/CompanyRepository.java | 7 + .../rest/ActivationCodeController.java | 38 ++++++ .../service/ActivationCodeService.java | 20 +++ .../service/WechatSendMessageService.java | 8 ++ .../service/dto/ActivationCodeDto.java | 30 ++++ .../impl/ActivationCodeServiceImpl.java | 86 ++++++++++++ .../service/impl/CompanyServiceImpl.java | 2 + .../impl/WechatSendMessageServiceImpl.java | 22 +++ .../mapstruct/ActivationCodeMapper.java | 12 ++ .../main/resources/config/application-dev.yml | 6 + .../resources/config/application-prod.yml | 4 + .../dto/ActivationCodeQueryCriteria.java | 14 ++ .../com/baiye/model/entity/BaseCompany.java | 4 + 16 files changed, 445 insertions(+) create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/ActivationRecord.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/httpRequest/ActivationCodeRequestApi.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/ActivationCodeRepository.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/ActivationCodeController.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/ActivationCodeService.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ActivationCodeDto.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/ActivationCodeServiceImpl.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/mapstruct/ActivationCodeMapper.java create mode 100644 ad-platform-pojo/src/main/java/com/baiye/model/dto/ActivationCodeQueryCriteria.java diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/ActivationRecord.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/ActivationRecord.java new file mode 100644 index 00000000..77f65a8b --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/ActivationRecord.java @@ -0,0 +1,56 @@ +package com.baiye.modules.platform.domain; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import org.hibernate.annotations.CreationTimestamp; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; + +@Entity +@Table(name = "tb_activation_record") +@ApiModel(value = "激活码记录表") +@EntityListeners(AuditingEntityListener.class) +@Getter +@Setter +public class ActivationRecord implements Serializable { + + private static final long serialVersionUID = 8623354712013889005L; + + @Id + @ApiModelProperty(value = "ID") + @Column(name = "activation_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long activationId; + + @ApiModelProperty(value = "激活码") + @Column(name = "activation_code") + private String activationCode; + + @ApiModelProperty(value = "所属用户ID") + @Column(name = "user_id") + private Long userId; + + @ApiModelProperty(value = "激活码类型 1-月卡;2-年卡;3:季卡") + @Column(name = "code_type") + private Integer codeType; + + @ApiModelProperty(value = "创建时间") + @Column(name = "create_time") + @CreationTimestamp + private java.util.Date createTime; + + public ActivationRecord(String activationCode, Long userId, Integer codeType) { + this.activationCode = activationCode; + this.userId = userId; + this.codeType = codeType; + } + + public ActivationRecord() { + + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/httpRequest/ActivationCodeRequestApi.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/httpRequest/ActivationCodeRequestApi.java new file mode 100644 index 00000000..18d34920 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/httpRequest/ActivationCodeRequestApi.java @@ -0,0 +1,128 @@ +package com.baiye.modules.platform.httpRequest; + +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.baiye.exception.BadRequestException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +@Slf4j +@Component +public class ActivationCodeRequestApi { + + @Value("${activation.url}") + private String URL; + + public void register(String name, String pwd) { + try { + Map map = new HashMap<>(); + map.put("name", name); + map.put("pwd", pwd); + String post = HttpUtil.post(URL + "/api/auth/registerByBaiye", JSONUtil.toJsonStr(map)); + JSONObject jsonObject = JSONUtil.parseObj(post); + String status = jsonObject.get("status").toString(); + if (!status.equals("200")) throw new BadRequestException("注册失败"); + } catch (Exception e) { + throw new BadRequestException("注册失败"); + } + } + + public JSONArray getActivationCode(int codeNum, int type, String account) { + try { + String url = URL + "/api/activate-code/genActivateCodeByBaiye"; + Map map = new HashMap<>(); + map.put("codeNum", codeNum); + map.put("type", type); + map.put("account", account); + String response = HttpUtil.get(url, map); + JSONObject jsonObject = JSONUtil.parseObj(response); + String status = jsonObject.get("status").toString(); + if (status.equals("200")) { + return JSONUtil.parseArray(jsonObject.get("data")); + } else { + throw new BadRequestException("激活失败"); + } + } catch (Exception e) { + throw new BadRequestException("激活失败"); + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/ActivationCodeRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/ActivationCodeRepository.java new file mode 100644 index 00000000..b272d28c --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/ActivationCodeRepository.java @@ -0,0 +1,8 @@ +package com.baiye.modules.platform.repository; + +import com.baiye.modules.platform.domain.ActivationRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface ActivationCodeRepository extends JpaRepository, JpaSpecificationExecutor { +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java index d8f2f3d5..55031299 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java @@ -131,4 +131,11 @@ public interface CompanyRepository extends JpaRepository, JpaSpec @Modifying @Query("UPDATE Company set companyType = ?1 where id = ?2") void updateCompanyTypeById(Integer companyType, Long companyId); + + /** + * 修改公司激活状态 + */ + @Modifying + @Query("UPDATE Company set isActivation = ?1 where id = ?2") + void updateCompanyIsActivationById(Integer isActivation, Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/ActivationCodeController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/ActivationCodeController.java new file mode 100644 index 00000000..b3ba8c29 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/rest/ActivationCodeController.java @@ -0,0 +1,38 @@ +package com.baiye.modules.platform.rest; + +import com.baiye.http.CommonResponse; +import com.baiye.model.dto.ActivationCodeQueryCriteria; +import com.baiye.model.dto.TaskQueryCriteria; +import com.baiye.modules.platform.service.ActivationCodeService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/activationRecord") +@Api(tags = "激活码管理") +public class ActivationCodeController { + + private final ActivationCodeService activationCodeService; + + @ApiOperation("生成激活码") + @GetMapping("/generate") + public CommonResponse generateActivationCode(@RequestParam("codeNum") int codeNum, @RequestParam("codeType") int codeType){ + activationCodeService.generateActivationCode(codeNum, codeType); + return CommonResponse.createBySuccess(); + } + + @ApiOperation("查询(分页)") + @GetMapping("/queryAll") + public ResponseEntity queryAll(ActivationCodeQueryCriteria activationCodeQueryCriteria, Pageable pageable) { + return new ResponseEntity<>(activationCodeService.queryAll(activationCodeQueryCriteria, pageable), HttpStatus.OK); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/ActivationCodeService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/ActivationCodeService.java new file mode 100644 index 00000000..d77f4783 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/ActivationCodeService.java @@ -0,0 +1,20 @@ +package com.baiye.modules.platform.service; + +import com.baiye.model.dto.ActivationCodeQueryCriteria; +import org.springframework.data.domain.Pageable; + +public interface ActivationCodeService { + + /** + * 生成激活码 + * + * @param codeNum 数量 + * @param codeType 激活码类型 1-月卡;2-年卡;3:季卡 -----注:月卡暂弃 + */ + void generateActivationCode(int codeNum, int codeType); + + /** + * 分页查询激活记录 + */ + Object queryAll(ActivationCodeQueryCriteria activationCodeQueryCriteria, Pageable pageable); +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/WechatSendMessageService.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/WechatSendMessageService.java index fba22bdd..dbcbe001 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/WechatSendMessageService.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/WechatSendMessageService.java @@ -104,4 +104,12 @@ public interface WechatSendMessageService { * @param id */ void deleteId(Long id); + + /** + * 个微激活码用户注册 + * @param namePrefix 前缀 + * @param name 名称 + * @param companyId 公司ID + */ + void register(String namePrefix, String name, Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ActivationCodeDto.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ActivationCodeDto.java new file mode 100644 index 00000000..60d19ff5 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/ActivationCodeDto.java @@ -0,0 +1,30 @@ +package com.baiye.modules.platform.service.dto; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class ActivationCodeDto implements Serializable { + + private static final long serialVersionUID = 7917504710223840272L; + + /** 防止精度丢失 */ + @JsonSerialize(using= ToStringSerializer.class) + private Long activationId; + + @ApiModelProperty(value = "激活码") + private String activationCode; + + @ApiModelProperty(value = "所属用户ID") + private Long userId; + + @ApiModelProperty(value = "激活码类型 1-月卡;2-年卡;3:季卡") + private Integer codeType; + + @ApiModelProperty(value = "创建时间") + private java.util.Date createTime; +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/ActivationCodeServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/ActivationCodeServiceImpl.java new file mode 100644 index 00000000..5d8173b2 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/ActivationCodeServiceImpl.java @@ -0,0 +1,86 @@ +package com.baiye.modules.platform.service.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.json.JSONArray; +import com.baiye.exception.BadRequestException; +import com.baiye.model.dto.ActivationCodeQueryCriteria; +import com.baiye.modules.platform.domain.ActivationRecord; +import com.baiye.modules.platform.domain.Company; +import com.baiye.modules.platform.httpRequest.ActivationCodeRequestApi; +import com.baiye.modules.platform.repository.ActivationCodeRepository; +import com.baiye.modules.platform.repository.CompanyRepository; +import com.baiye.modules.platform.service.ActivationCodeService; +import com.baiye.modules.platform.service.CompanyService; +import com.baiye.modules.platform.service.WechatSendMessageService; +import com.baiye.modules.platform.service.mapstruct.ActivationCodeMapper; +import com.baiye.util.PageUtil; +import com.baiye.util.QueryHelp; +import com.baiye.util.SecurityUtils; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ActivationCodeServiceImpl implements ActivationCodeService { + + private final ActivationCodeRepository activationCodeRepository; + + private final CompanyRepository companyRepository; + + private final ActivationCodeRequestApi activationCodeRequestApi; + + private final ActivationCodeMapper activationCodeMapper; + + private final CompanyService companyService; + + private final WechatSendMessageService wechatSendMessageService; + + @Value("${activation.namePrefix}") + private String namePrefix; + + @Override + @Transactional(rollbackFor = Exception.class) + public void generateActivationCode(int codeNum, int codeType) { + Long currentUserId = SecurityUtils.getCurrentUserId(); + String name = namePrefix + currentUserId; + Company company = companyRepository.findByUserId(currentUserId); + Integer isActivation = company.getIsActivation(); + // 未激活过,先进行注册 + if (isActivation == 0) wechatSendMessageService.register(namePrefix, name, company.getId()); + // 计费,默认季卡 + double price = 300.00; + if (codeType == 2) price = 1080.00; + double totalPrice = company.getUserBalance() - (codeNum * price); + if (totalPrice < 0) throw new BadRequestException("余额不足"); + // 生成激活码 + JSONArray array = activationCodeRequestApi.getActivationCode(codeNum, codeType, name); + if (CollUtil.isNotEmpty(array)) { + // 扣费 + companyService.updateUserBalanceByCompanyId(totalPrice, company.getId()); + // 插入激活码记录 + List list = new ArrayList<>(); + for (Object obj : array) { + ActivationRecord activationRecord = new ActivationRecord((String) obj, currentUserId, codeType); + list.add(activationRecord); + } + activationCodeRepository.saveAll(list); + } + } + + @Override + public Object queryAll(ActivationCodeQueryCriteria criteria, Pageable pageable) { + PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime")); + criteria.setUserId(SecurityUtils.getCurrentUserId()); + Page page = activationCodeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageRequest); + return PageUtil.toPage(page.map(activationCodeMapper::toDto)); + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java index 9b770264..aade196c 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java @@ -74,6 +74,7 @@ public class CompanyServiceImpl implements CompanyService { byUserId.setApplicationTime(DateUtil.date()); byUserId.setCompanyCode(byUserId.getCompanyName().trim()); byUserId.setSonUserNum(100); + byUserId.setIsActivation(DefaultNumberConstants.ZERO_NUMBER); userRepository.updateStatusById(Boolean.FALSE, SecurityUtils.getCurrentUserId()); return companyMapper.toDto(companyRepository.save(byUserId)); } @@ -107,6 +108,7 @@ public class CompanyServiceImpl implements CompanyService { Company company = new Company(); BeanUtil.copyProperties(companyDto, company); company.setSonUserNum(100); + company.setIsActivation(DefaultNumberConstants.ZERO_NUMBER); return companyMapper.toDto(companyRepository.save(company)); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/WechatSendMessageServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/WechatSendMessageServiceImpl.java index 0a598a6e..59feea1a 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/WechatSendMessageServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/WechatSendMessageServiceImpl.java @@ -19,7 +19,10 @@ import cn.hutool.core.util.ObjectUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; import com.baiye.model.enums.ResponseCode; +import com.baiye.modules.platform.domain.Company; import com.baiye.modules.platform.domain.WechatSendMessage; +import com.baiye.modules.platform.httpRequest.ActivationCodeRequestApi; +import com.baiye.modules.platform.repository.CompanyRepository; import com.baiye.modules.platform.repository.WechatSendMessageRepository; import com.baiye.modules.platform.service.WechatSendMessageService; import com.baiye.modules.platform.service.dto.WechatSendMessageDto; @@ -30,6 +33,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; @@ -51,6 +55,8 @@ public class WechatSendMessageServiceImpl implements WechatSendMessageService { private final WechatSendMessageRepository wechatSendMessageRepository; private final WechatSendMessageMapper wechatSendMessageMapper; + private final CompanyRepository companyRepository; + private final ActivationCodeRequestApi activationCodeRequestApi; @Override public Map queryAll(WechatSendMessageQueryCriteria criteria, Pageable pageable) { @@ -148,4 +154,20 @@ public class WechatSendMessageServiceImpl implements WechatSendMessageService { wechatSendMessageRepository.deleteById(id); } + + /** + * Propagation.REQUIRES_NEW: + * 1、会新开启事务,外层事务不会影响内部事务的提交/回滚 + * 2、内部事务的异常,会影响外部事务的回滚 + * 3、同service事务无效,spring通过TransactionInterceptor类来控制事务开启、提交、回滚,它会创建一个目标类的代理类-generateActivationCode方法调用register()方法, + * this调用本身的方法register()方法并不会开启新事物. + */ + @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) + public void register(String namePrefix, String name, Long companyId) { + String pwd = namePrefix + "123456"; + activationCodeRequestApi.register(name, pwd); + // 修改公司激活状态 + companyRepository.updateCompanyIsActivationById(DefaultNumberConstants.ONE_NUMBER, companyId); + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/mapstruct/ActivationCodeMapper.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/mapstruct/ActivationCodeMapper.java new file mode 100644 index 00000000..c3560f98 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/mapstruct/ActivationCodeMapper.java @@ -0,0 +1,12 @@ +package com.baiye.modules.platform.service.mapstruct; + +import com.baiye.model.base.BaseMapper; +import com.baiye.modules.platform.domain.ActivationRecord; +import com.baiye.modules.platform.domain.Label; +import com.baiye.modules.platform.service.dto.ActivationCodeDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface ActivationCodeMapper extends BaseMapper { +} diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml index c4b9fd82..9a453249 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-dev.yml @@ -197,3 +197,9 @@ ocean: ad-back: url: cb.tuoz.net/api/ad-platform/tag token: 4f41de7d-97a3-4a40-b682-b9fc73b92459 + +activation: + url: http://81.69.250.46:18877 + namePrefix: by_ + # url: fission-server.xhuatea.com + # namePrefix: by_zs_ diff --git a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml index f5f191fb..98c4ab10 100644 --- a/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml +++ b/ad-platform-manage/ad-platform-management/src/main/resources/config/application-prod.yml @@ -195,3 +195,7 @@ ocean: ad-back: url: cb.tuoz.net/api/ad-platform/tag token: 4f41de7d-97a3-4a40-b682-b9fc73b92459 + +activation: + url: fission-server.xhuatea.com + namePrefix: by_ diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/dto/ActivationCodeQueryCriteria.java b/ad-platform-pojo/src/main/java/com/baiye/model/dto/ActivationCodeQueryCriteria.java new file mode 100644 index 00000000..8ec7175a --- /dev/null +++ b/ad-platform-pojo/src/main/java/com/baiye/model/dto/ActivationCodeQueryCriteria.java @@ -0,0 +1,14 @@ +package com.baiye.model.dto; + +import com.baiye.annotation.Query; +import lombok.Data; + +@Data +public class ActivationCodeQueryCriteria { + + @Query + private String activationCode; + + @Query + private Long userId; +} diff --git a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCompany.java b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCompany.java index d9b519eb..e1c8b429 100644 --- a/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCompany.java +++ b/ad-platform-pojo/src/main/java/com/baiye/model/entity/BaseCompany.java @@ -134,4 +134,8 @@ public class BaseCompany extends BaseEntity implements Serializable { @ApiModelProperty("子用户数量") @Column(name = "son_user_num") private Integer sonUserNum; + + @ApiModelProperty("公司是否激活 0:未激活 1:激活过") + @Column(name = "is_activation") + private Integer isActivation; } From 8edca3ca77f77452062e68a38e8eb7306565fd6e Mon Sep 17 00:00:00 2001 From: wujingtao Date: Mon, 6 Feb 2023 10:22:14 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E9=80=9A=E8=AF=9D=E8=B4=B9=E7=94=A8bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TelephoneCallServiceImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java index 9420eb76..1dd0ddf4 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/telemarkting/service/impl/TelephoneCallServiceImpl.java @@ -282,6 +282,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { telephoneCallStopDTO.setCallId(requestId); return CommonResponse.createBySuccess(telephoneCallStopDTO); } + @Override public CommonResponse rollCallStop(TelephoneCallStopDTO telephoneCallStopDTO) { if (rollCallReq.stopReq(telephoneCallStopDTO)) { @@ -289,6 +290,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { } return CommonResponse.createByError(); } + /** * 点呼回调 会得到两个,一个是针对分机号 一个是针对真实被叫 保存信息取值被叫回调,录音取分机号回调(被叫回调没有录音) * @@ -424,16 +426,19 @@ public class TelephoneCallServiceImpl implements TelephoneCallService { * @param duration * @return */ - private Double dealDuration(int duration) { + private double dealDuration(int duration) { if (duration <= DefaultNumberConstants.SIXTY) { return 1.00; } else { + //余数 int i = duration % 60; - double div = NumberUtil.div(duration, 60); + //整数 + int q = duration / 60; + if (i > 0) { - return NumberUtil.add(div, 1); + return NumberUtil.add(q, 1); } else { - return div; + return q; } } } From 6c73fd65294c4afebdac06dc99c138d736314b2f Mon Sep 17 00:00:00 2001 From: wujingtao Date: Tue, 14 Feb 2023 13:16:56 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=B6=88=E8=B4=B9?= =?UTF-8?q?=E5=92=8C=E4=BD=99=E9=A2=9D=EF=BC=8C=E9=80=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/baiye/feign/SourceClueClient.java | 1 + .../modules/platform/domain/Company.java | 2 + .../repository/CallDeductRepository.java | 29 ++++-- .../repository/CompanyRepository.java | 5 ++ .../service/dto/AliPayQueryCriteria.java | 8 +- .../platform/service/dto/CompanyDto.java | 3 + .../service/impl/CompanyServiceImpl.java | 10 +++ .../modules/report/api/ReportController.java | 6 ++ .../report/dao/ReportDeductRepository.java | 30 +++++++ .../modules/report/entity/ReportDeduct.java | 51 +++++++++++ .../report/service/QueryReportService.java | 5 ++ .../service/impl/QueryReportServiceImpl.java | 68 ++++++++++++++ .../com/baiye/timed/ReportDeductsSync.java | 90 +++++++++++++++++++ .../main/java/com/baiye/timed/ReportSync.java | 10 ++- .../module/controller/ClueController.java | 1 + .../controller/ReportTokerController.java | 9 +- .../java/com/baiye/module/dao/ClueJpa.java | 38 ++++++++ .../module/dao/ClueMiddleRepository.java | 2 +- .../baiye/module/dao/ClueTalkRepository.java | 11 ++- .../module/dao/ReportTokerCallRepository.java | 28 ++++++ .../baiye/module/entity/ReportTokerCall.java | 63 +++++++++++++ .../module/service/ReportTokerService.java | 3 + .../baiye/module/service/dto/ClueTalkDTO.java | 17 ++++ .../service/impl/ReportTokerServiceImpl.java | 60 +++++++++++-- .../java/com/baiye/task/OceanEngineSync.java | 1 + .../main/java/com/baiye/task/ReportSync.java | 59 +++++++++++- 26 files changed, 587 insertions(+), 23 deletions(-) create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/ReportDeductRepository.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/entity/ReportDeduct.java create mode 100644 ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java create mode 100644 ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerCallRepository.java create mode 100644 ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ReportTokerCall.java create mode 100644 ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueTalkDTO.java 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 2a2a14c1..57011f58 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 @@ -1,5 +1,6 @@ package com.baiye.feign; +import com.baiye.annotation.Inner; import com.baiye.feign.callback.SourceClueClientFallback; import com.baiye.http.CommonResponse; import com.baiye.model.dto.ClueQueryCriteria; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Company.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Company.java index a89aaa9f..bd3bd09d 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Company.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/domain/Company.java @@ -28,4 +28,6 @@ public class Company extends BaseCompany implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Transient + private Double deductAmount; } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java index 6a624875..62fc04a7 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CallDeductRepository.java @@ -26,13 +26,14 @@ import java.util.Date; import java.util.List; /** -* @author Enzo -* @date 2022-11-9 -*/ + * @author Enzo + * @date 2022-11-9 + */ public interface CallDeductRepository extends JpaRepository, JpaSpecificationExecutor { /** * 时间查找 + * * @param companyId * @param beginTime * @param endTime @@ -43,10 +44,9 @@ public interface CallDeductRepository extends JpaRepository, J List findByCompanyIdAndTime(Long companyId, Date beginTime, Date endTime); - - /** * 公司id查找记录 + * * @param companyId * @param parse * @param endDate @@ -54,4 +54,23 @@ public interface CallDeductRepository extends JpaRepository, J */ @Query(value = "from CallDeduct where companyId = ?1 and createTime >= ?2 and createTime <= ?3") List queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate); + + /** + * 公司id查找记录 + * + * @param parse + * @param endDate + * @return + */ + @Query(value = "from CallDeduct where createTime >= ?1 and createTime <= ?2") + List queryByCompanyIdAndTime(DateTime parse, DateTime endDate); + + /** + * 根据公司id查询所有消费合计 + * + * @param companyId + * @return + */ + @Query(value = "select sum(deductAmount) as deductAmout from CallDeduct where companyId = ?1 ") + Double sumDeductAmountByCompanyId(Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java index 55031299..1850665f 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/repository/CompanyRepository.java @@ -22,6 +22,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -138,4 +139,8 @@ public interface CompanyRepository extends JpaRepository, JpaSpec @Modifying @Query("UPDATE Company set isActivation = ?1 where id = ?2") void updateCompanyIsActivationById(Integer isActivation, Long companyId); + + + @Query(value = "select id, user_balance as userBalance from tb_company where 1=1 and (coalesce (?1,null) is null or id = ?1)", nativeQuery = true) + List> findUserBalanceByUserId(Long companyId); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/AliPayQueryCriteria.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/AliPayQueryCriteria.java index 27910f05..e1eb3b6b 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/AliPayQueryCriteria.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/AliPayQueryCriteria.java @@ -23,9 +23,9 @@ import java.sql.Timestamp; import java.util.List; /** -* @author Zheng Jie -* @date 2022-03-25 -*/ + * @author Zheng Jie + * @date 2022-03-25 + */ @Data @DataPermission(fieldName = "id") public class AliPayQueryCriteria { @@ -33,6 +33,8 @@ public class AliPayQueryCriteria { @Query private Integer status; + @Query + private Long companyId; private Boolean sortBy; diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CompanyDto.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CompanyDto.java index 1649ff69..7fc00d95 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CompanyDto.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/dto/CompanyDto.java @@ -111,4 +111,7 @@ public class CompanyDto extends BaseDTO implements Serializable { @ApiModelProperty("dmp上传数量") private Integer dmpLimitNum; + + @ApiModelProperty("消费合计") + private Double deductAmount; } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java index aade196c..3ae23789 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/platform/service/impl/CompanyServiceImpl.java @@ -7,9 +7,11 @@ import com.baiye.constant.DefaultNumberConstants; import com.baiye.exception.BadRequestException; import com.baiye.exception.EntityExistException; import com.baiye.model.enums.ResponseCode; +import com.baiye.modules.platform.domain.CallDeduct; import com.baiye.modules.platform.domain.Company; import com.baiye.modules.platform.domain.PayFatherTemplate; import com.baiye.modules.platform.domain.vo.CompanyComboVO; +import com.baiye.modules.platform.repository.CallDeductRepository; import com.baiye.modules.platform.repository.CompanyRepository; import com.baiye.modules.system.repository.UserRepository; import com.baiye.modules.platform.service.AgentService; @@ -53,6 +55,7 @@ public class CompanyServiceImpl implements CompanyService { private final AgentService agentService; + private final CallDeductRepository callDeductRepository; @Override @Transactional(rollbackFor = Exception.class) @@ -83,6 +86,13 @@ public class CompanyServiceImpl implements CompanyService { public Map queryAll(CompanyQueryCriteria criteria, Pageable pageable) { Page page = companyRepository.findAll ((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable); + //公司消费总额 + for (Company company : page) { + //公司id + Long id = company.getId(); + Double deductAmount = callDeductRepository.sumDeductAmountByCompanyId(id); + company.setDeductAmount(deductAmount); + } return PageUtil.toPage(page.map(companyMapper::toDto).getContent(), page.getTotalElements()); } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/api/ReportController.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/api/ReportController.java index 6a618b79..89006cf2 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/api/ReportController.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/api/ReportController.java @@ -102,4 +102,10 @@ public class ReportController { public void downloadCallRecordDetails(HttpServletResponse response, Long clueId) { queryReportService.downloadCallRecordDetails(response, clueId); } + + @PostMapping("/report/deduct") + @ApiOperation("统计公司的消费情况") + public CommonResponse reportDeduct(@RequestBody StatisticalReportDTO statisticalReportDTO) { + return queryReportService.reportDeduct(statisticalReportDTO); + } } diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/ReportDeductRepository.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/ReportDeductRepository.java new file mode 100644 index 00000000..816bd644 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/dao/ReportDeductRepository.java @@ -0,0 +1,30 @@ +package com.baiye.modules.report.dao; + +import cn.hutool.core.date.DateTime; +import com.baiye.modules.platform.domain.CallDeduct; +import com.baiye.modules.report.entity.ReportDeduct; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author jt + */ +@Repository +public interface ReportDeductRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 公司id查找记录 + * + * @param companyId + * @param parse + * @param endDate + * @return + */ + @Query(value = "from ReportDeduct where companyId = ?1 and createTime >= ?2 and createTime <= ?3") + List queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate); + +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/entity/ReportDeduct.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/entity/ReportDeduct.java new file mode 100644 index 00000000..4f3b4029 --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/modules/report/entity/ReportDeduct.java @@ -0,0 +1,51 @@ +package com.baiye.modules.report.entity; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * @author jt + */ +@Getter +@Setter +@Entity +@Table(name = "tb_report_deduct") +@EntityListeners(AuditingEntityListener.class) +@AllArgsConstructor +public class ReportDeduct implements Serializable { + + @Id + @ApiModelProperty(value = "主键id(自动递增)") + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @LastModifiedDate + @Column(name = "create_time") + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "消费额") + @Column(name = "deduct_amount") + private Double deductAmount; + + @ApiModelProperty(value = "余额") + @Column(name = "balance") + private Double balance; + + @ApiModelProperty(value = "管理员id") + @Column(name = "company_id") + private Long companyId; + + public ReportDeduct() { + + } +} 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 bd5e5a0f..cefb1278 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 @@ -69,4 +69,9 @@ public interface QueryReportService { * 导出线索的通话记录详情 */ void downloadCallRecordDetails(HttpServletResponse response, Long clueId); + + /** + * 查询线索的通话详情 + */ + CommonResponse reportDeduct(StatisticalReportDTO s); } 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 d95a350c..653a578d 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 @@ -3,6 +3,7 @@ package com.baiye.modules.report.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.date.DateTime; import cn.hutool.core.date.DateUnit; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.NumberUtil; @@ -16,8 +17,12 @@ import com.baiye.http.CommonResponse; import com.baiye.model.enums.ClueStageEnum; import com.baiye.model.enums.ResponseCode; import com.baiye.model.vo.ResSourceLabel; +import com.baiye.modules.platform.domain.CallDeduct; +import com.baiye.modules.platform.repository.CallDeductRepository; +import com.baiye.modules.report.dao.ReportDeductRepository; import com.baiye.modules.report.dao.TaskReportRepository; import com.baiye.modules.report.dao.UserReportRepository; +import com.baiye.modules.report.entity.ReportDeduct; import com.baiye.modules.report.entity.TaskReport; import com.baiye.modules.report.entity.UserReport; import com.baiye.modules.report.entity.dto.CallRecordDetailsDTO; @@ -39,10 +44,12 @@ import com.baiye.modules.telemarkting.dao.CallClueRepository; import com.baiye.modules.telemarkting.entity.AllCallInfo; import com.baiye.modules.telemarkting.entity.CallClueInfo; import com.baiye.modules.telemarkting.entity.ClueMiddle; +import com.baiye.timed.ReportDeductsSync; import com.baiye.timed.ReportSync; import com.baiye.util.DateTimeUtil; import com.baiye.util.ExportExcelUtil; import com.baiye.util.SecurityUtils; +import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.Cacheable; @@ -72,7 +79,10 @@ public class QueryReportServiceImpl implements QueryReportService { private final UserRepository userRepository; private final CallClueRepository callClueRepository; private final ReportSync reportSync; + private final ReportDeductsSync reportDeductsSync; private final UserService userService; + private final CallDeductRepository callDeductRepository; + private final ReportDeductRepository reportDeductRepository; /** * 统计 公司下所有任务的合并 @@ -660,6 +670,64 @@ public class QueryReportServiceImpl implements QueryReportService { ExportExcelUtil.downloadEasyExcel(response, CallRecordDetailsDTO.class, listDto); } + @Override + public CommonResponse reportDeduct(StatisticalReportDTO s) { + if (s.getCompanyId() == null) { + throw new BadRequestException("公司id为空"); + } + DateTime beginTime; + DateTime endTime; + if (StrUtil.isBlank(s.getBeginTime()) || StrUtil.isBlank(s.getEndTime())) { + //初始为7天 + DateTime yesterday = DateUtil.yesterday(); + Date date = DateUtil.offsetDay(yesterday, -6); + beginTime = DateUtil.beginOfDay(date); + endTime = DateUtil.endOfDay(yesterday); + } else { + beginTime = DateUtil.parseDateTime(s.getBeginTime()); + endTime = DateUtil.parseDateTime(s.getEndTime()); + } + + List reportDeducts = reportDeductRepository.queryByCompanyIdAndTime(s.getCompanyId(), beginTime, endTime); + + // 需要实时查询当天的统计 + if (judgmentDate(endTime, DateUtil.parseDate(DateUtil.today()))) { + DateTime statTime = DateUtil.beginOfDay(DateUtil.date()); + List reportDeducts1 = reportDeductsSync.reportDeducts(statTime, endTime, s.getCompanyId()); + reportDeducts.addAll(reportDeducts1); + } + List> maps = new ArrayList<>(); + if (CollUtil.isEmpty(reportDeducts)) { + return CommonResponse.createBySuccess(maps); + } + Map callMap = new HashMap<>(); + for (ReportDeduct reportDeduct : reportDeducts) { + String createTime = DateUtil.format(reportDeduct.getCreateTime(), "yyyy-MM-dd"); + callMap.put(createTime, reportDeduct); + } + long betweenDay = DateUtil.between(beginTime, endTime, DateUnit.DAY); + + for (int i = 0; i <= betweenDay; i++) { + String time = DateUtil.format(DateUtil.offsetDay(beginTime, i), "yyyy-MM-dd"); + Map map = new HashMap<>(4); + if (callMap.containsKey(time)) { + ReportDeduct reportDeduct = callMap.get(time); + map.put("balance", reportDeduct.getBalance()); + map.put("deductAmount", reportDeduct.getDeductAmount()); + } else { + map.put("balance", 0); + map.put("deductAmount", 0); + } + map.put("time", time); + maps.add(map); + } + return CommonResponse.createBySuccess(maps); + } + + private static Boolean judgmentDate(Date time, Date date) { + return DateUtil.betweenDay(time, date, true) == DefaultNumberConstants.ZERO_NUMBER; + } + /** * 对传入得条件进行处理 */ diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java new file mode 100644 index 00000000..f12fe9fb --- /dev/null +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java @@ -0,0 +1,90 @@ +package com.baiye.timed; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.baiye.modules.platform.domain.CallDeduct; +import com.baiye.modules.platform.repository.CallDeductRepository; +import com.baiye.modules.platform.repository.CompanyRepository; +import com.baiye.modules.report.dao.ReportDeductRepository; +import com.baiye.modules.report.entity.ReportDeduct; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.math.BigInteger; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author jt + */ +@Slf4j +@Component +public class ReportDeductsSync { + @Resource + private CompanyRepository companyRepository; + @Resource + private ReportDeductRepository repository; + @Resource + private CallDeductRepository callDeductRepository; + + // @Scheduled(cron = "0 0/5 * * * ? ") + @Scheduled(cron = "0 0 22 * * ? ") + @Transactional(rollbackFor = Exception.class) + public void countReport() { + log.info("++++++++++++++++++++++countReport deduct start time {} ++++++++++++++++", DateUtil.now()); + String beginOfDay = DateUtil.formatDateTime(DateUtil.yesterday()); + String endOfDay = DateUtil.formatDateTime(DateUtil.date()); + //统计每个公司的消费额 + List reportDeducts = reportDeducts(DateUtil.parseDateTime(beginOfDay), DateUtil.parseDateTime(endOfDay), null); + repository.saveAll(reportDeducts); + log.info("++++++++++++++++++++++countReport deduct end time {} ++++++++++++++++", DateUtil.now()); + } + + public List reportDeducts(DateTime beginOfDay, DateTime endOfDay, Long companyId) { + + List> userBalances = companyRepository.findUserBalanceByUserId(companyId); + HashMap map = new HashMap<>(); + for (Map map1 : userBalances) { + BigInteger key = (BigInteger) map1.get("id"); + Long id = key.longValue(); + Double value = (Double) map1.get("userBalance"); + map.put(id, value); + } + + List list = new ArrayList<>(); + List callDeducts; + if (companyId != null) { + callDeducts = callDeductRepository.queryByCompanyIdAndTime(companyId, beginOfDay, endOfDay); + Double sum = callDeducts.stream().mapToDouble(CallDeduct::getDeductAmount).sum(); + ReportDeduct reportDeduct = new ReportDeduct(); + reportDeduct.setDeductAmount(sum); + reportDeduct.setBalance(map.get(companyId)); + reportDeduct.setCreateTime(new Date()); + reportDeduct.setCompanyId(companyId); + list.add(reportDeduct); + } else { + callDeducts = callDeductRepository.queryByCompanyIdAndTime(beginOfDay, endOfDay); + Map> collect = callDeducts.stream().collect(Collectors.groupingBy(CallDeduct::getCompanyId, Collectors.toList())); + for (Long key : map.keySet()) { + ReportDeduct reportDeduct = new ReportDeduct(); + reportDeduct.setBalance(map.get(key)); + reportDeduct.setCreateTime(new Date()); + reportDeduct.setCompanyId(key); + List callDeducts1 = collect.get(key); + + if (CollUtil.isEmpty(callDeducts1)) { + reportDeduct.setDeductAmount(0.0); + } else { + Double sum = callDeducts1.stream().mapToDouble(CallDeduct::getDeductAmount).sum(); + reportDeduct.setDeductAmount(sum); + } + list.add(reportDeduct); + } + } + return list; + } +} diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportSync.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportSync.java index c4e061c9..3baff3fd 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportSync.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportSync.java @@ -26,10 +26,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -49,10 +48,14 @@ public class ReportSync { private final UserReportRepository userReportRepository; private final SourceClueClient sourceClueClient; + /** * 每天晚上23点,定时统计外呼信息 */ + +// @Scheduled(cron = "0 0/5 * * * ? ") @Scheduled(cron = "0 0 23 * * ? ") + @Transactional(rollbackFor = Exception.class) public void countReport() { log.info("++++++++++++++++++++++countReport Sync start time {} ++++++++++++++++", DateUtil.now()); String beginOfDay = DateUtil.formatDateTime(DateUtil.yesterday()); @@ -71,6 +74,7 @@ public class ReportSync { log.info("++++++++++++++++++++++countReport Sync end time {} ++++++++++++++++", DateUtil.now()); } + public List autoCountReportByTask(String beginOfDay, String endOfDay, List callClueInfos) { //根据任务id分组 HashMap> map = new HashMap<>(callClueInfos.stream().collect(Collectors.groupingBy(CallClueInfo::getTaskId, Collectors.toList()))); 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 2638b547..ec008c49 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 @@ -168,6 +168,7 @@ public class ClueController { @ApiOperation("按任务获取当日所有意向数据") @GetMapping("/countClueByTaskId") + @Inner(value = false) public CommonResponse countClueByTaskId(@RequestParam(value = "taskId") Long taskId, @RequestParam(value = "beginTime") String beginTime, @RequestParam(value = "endTime") String endTime) { diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportTokerController.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportTokerController.java index b900ea5d..b34411fc 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportTokerController.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportTokerController.java @@ -1,6 +1,5 @@ package com.baiye.module.controller; -import com.baiye.annotation.Inner; import com.baiye.http.CommonResponse; import com.baiye.model.dto.HomePageReportDTO; import com.baiye.model.dto.ReportStageAndTurnoverDto; @@ -13,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.util.List; import java.util.Map; /** @@ -57,5 +57,10 @@ public class ReportTokerController { return reportTokerService.getReportHomePage(userId); } - + @GetMapping("/call") + public CommonResponse>> getReportCallInfo(@RequestParam(value = "beginTime") String beginTime, + @RequestParam(value = "endTime") String endTime + ) { + return reportTokerService.getReportCallInfo(beginTime, endTime); + } } 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 8b9e5bbd..d38bc695 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 @@ -13,6 +13,7 @@ import com.baiye.model.dto.ClueQueryCriteria; import com.baiye.model.dto.PublicCluePoolDto; import com.baiye.model.dto.PublicCluePoolQueryCriteria; import com.baiye.model.vo.ResSourceLabel; +import com.baiye.module.service.dto.ClueTalkDTO; import com.baiye.util.AESUtils; import com.baiye.util.RedisUtils; import lombok.extern.slf4j.Slf4j; @@ -499,4 +500,41 @@ public class ClueJpa { } return clueDtoList; } + + /** + * 查询线索通话情况 + * + * @param beginTime + * @param endTime + * @return + */ + @Transactional(rollbackOn = Exception.class) + public List getReportCallInfo(String beginTime, String endTime, Long managerId) { + StringBuilder sql = new StringBuilder("select tcm.newest_call_time as newestCallTime,tcm.clue_call_status as clueCallStatus ,tc.create_by as managerId " + + "from tb_clue_talk as tcm left join tb_clue as tc on tcm.clue_id =tc.id " + + " where tcm.newest_call_time between :beginTime and :endTime "); + if (managerId != null) { + sql.append(" and tc.create_by = :managerId"); + } + Query query = entityManager.createNativeQuery(sql.toString()); + query.setParameter("beginTime", beginTime); + query.setParameter("endTime", endTime); + if (managerId != null) { + query.setParameter("managerId", managerId); + } + query.unwrap(NativeQueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP); + List list = query.getResultList(); + List clueDtoList = new ArrayList<>(); + + for (Object obj : list) { + Map row = (Map) obj; + ClueTalkDTO clueDto = new ClueTalkDTO(); + BigInteger id = (BigInteger) row.get("managerId"); + clueDto.setManagerId(id.longValue()); + clueDto.setClueCallStatus((Integer) row.get("clueCallStatus")); + clueDto.setNewestCallTime((Date) row.get("newestCallTime")); + clueDtoList.add(clueDto); + } + return clueDtoList; + } } 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 b4b8bb00..8366798e 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 @@ -143,7 +143,7 @@ public interface ClueMiddleRepository extends JpaRepository, J * 查询任务数量 */ @Query(value = "SELECT task_id as taskId,count(*) as num FROM `tb_clue_middle` where task_id in ?1 GROUP BY task_id", nativeQuery = true) - List> findTaskIdCount(Set taskIds); + List> findTaskIdCount(Set taskIds); @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) diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java index 8602ca46..bb5213cd 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueTalkRepository.java @@ -1,6 +1,8 @@ package com.baiye.module.dao; +import com.baiye.module.entity.ClueMiddle; import com.baiye.module.entity.ClueTalk; +import com.baiye.module.service.dto.ClueTalkDTO; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; @@ -50,7 +52,14 @@ public interface ClueTalkRepository extends JpaRepository, JpaSp " where tc.create_by = ?1", nativeQuery = true) List findClueTalkByCreateBy(Long userId); - + /** + * 查询公司下线索数量 + * @param userId + * @return + */ + @Query(value = " select count(*) from tb_clue_talk as tcm left join tb_clue as tc on tcm.clue_id =tc.id" + + " where tc.create_by = ?1", nativeQuery = true) + Integer countAllByCreateBy(Long userId); /** * 查询任务总数 * diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerCallRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerCallRepository.java new file mode 100644 index 00000000..fda78ac1 --- /dev/null +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/ReportTokerCallRepository.java @@ -0,0 +1,28 @@ +package com.baiye.module.dao; + +import com.baiye.module.entity.ReportToker; +import com.baiye.module.entity.ReportTokerCall; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.List; + +/** + * @author jt + */ +@Repository +public interface ReportTokerCallRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 统计投客任务 + * + * @param beginTime + * @param endTime + * @param managerId + * @return + */ + @Query(value = "select * from tb_report_toker_call where (create_time between ?1 and ?2) and manager_id = ?3", nativeQuery = true) + List queryAllByTimeAndManagerId(String beginTime, String endTime,Long managerId); +} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ReportTokerCall.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ReportTokerCall.java new file mode 100644 index 00000000..5f945d48 --- /dev/null +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/ReportTokerCall.java @@ -0,0 +1,63 @@ +package com.baiye.module.entity; + +import cn.hutool.core.date.DateUtil; +import com.baiye.model.dto.HomePageReportDTO; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import io.swagger.annotations.ApiModelProperty; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.util.Date; + +@Setter +@Getter +@Entity +@Table(name = "tb_report_toker_call") +@EntityListeners(AuditingEntityListener.class) +public class ReportTokerCall { + @Id + @ApiModelProperty(value = "主键id(自动递增)") + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "create_time") + @ApiModelProperty(value = "创建时间") + @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8") + private Date createTime; + + @ApiModelProperty(value = "使用数") + @Column(name = "usr_num") + private Integer usrNum; + + @ApiModelProperty(value = "使用率") + @Column(name = "usr_num_rate") + private Double usrNumRate; + + @ApiModelProperty(value = "接通数") + @Column(name = "turn_on_num") + private Integer turnOnNum; + + @ApiModelProperty(value = "接通率") + @Column(name = "turn_on_rate") + private Double turnOnRate; + + @ApiModelProperty(value = "业务管理员") + @Column(name = "manager_id") + @JsonSerialize(using = ToStringSerializer.class) + private Long managerId; + + public ReportTokerCall init() { + this.setCreateTime(DateUtil.date()); + this.setUsrNum(0); + this.setUsrNumRate(0.00); + this.setTurnOnNum(0); + this.setTurnOnRate(0.00); + return this; + } +} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportTokerService.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportTokerService.java index ce379759..db20a962 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportTokerService.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportTokerService.java @@ -3,6 +3,7 @@ package com.baiye.module.service; import com.baiye.http.CommonResponse; import com.baiye.model.dto.HomePageReportDTO; import com.baiye.model.dto.ReportStageAndTurnoverDto; +import com.baiye.module.entity.ReportTokerCall; import com.baiye.module.entity.dto.ReportTokerDTO; import javax.servlet.http.HttpServletResponse; @@ -23,4 +24,6 @@ public interface ReportTokerService { CommonResponse reportClueStage(ReportStageAndTurnoverDto reportStageAndTurnoverDto); CommonResponse> getReportHomePage(Long userId); + + CommonResponse>> getReportCallInfo(String beginTime, String endTime); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueTalkDTO.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueTalkDTO.java new file mode 100644 index 00000000..d6b9ba89 --- /dev/null +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/dto/ClueTalkDTO.java @@ -0,0 +1,17 @@ +package com.baiye.module.service.dto; + +import lombok.*; + +import java.util.Date; + +/** + * @author jt + */ +@Data +public class ClueTalkDTO { + private Long managerId; + + private Date newestCallTime; + + private Integer clueCallStatus; +} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java index b0d91bd7..c31d50dc 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java @@ -22,11 +22,9 @@ import com.baiye.model.dto.HomePageReportDTO; import com.baiye.model.dto.ReportStageAndTurnoverDto; import com.baiye.module.dao.ClueMiddleRepository; import com.baiye.module.dao.ClueTalkRepository; +import com.baiye.module.dao.ReportTokerCallRepository; import com.baiye.module.dao.ReportTokerRepository; -import com.baiye.module.entity.ClueMiddle; -import com.baiye.module.entity.ClueTalk; -import com.baiye.module.entity.ReportToker; -import com.baiye.module.entity.Task; +import com.baiye.module.entity.*; import com.baiye.module.entity.dto.ReportTokerDTO; import com.baiye.module.entity.dto.UploadTokerDTO; import com.baiye.module.service.ReportTokerService; @@ -57,6 +55,7 @@ public class ReportTokerServiceImpl implements ReportTokerService { private final ClueMiddleRepository clueMiddleRepository; private final ClueTalkRepository clueTalkRepository; private final OrganizeClient organizeClient; + private final ReportTokerCallRepository reportTokerCallRepository; @Override public List> reportTokerBroken(ReportTokerDTO reportTokerDTO) { @@ -396,6 +395,55 @@ public class ReportTokerServiceImpl implements ReportTokerService { return list; } + @Override + public CommonResponse>> getReportCallInfo(String beginTime, String endTime) { + if (StrUtil.isBlank(beginTime) || StrUtil.isBlank(endTime)) { + //初始为7天 + DateTime yesterday = DateUtil.yesterday(); + Date date = DateUtil.offsetDay(yesterday, -6); + beginTime = DateUtil.format(DateUtil.beginOfDay(date), "yyyy-MM-dd HH:mm:ss"); + endTime = DateUtil.format(DateUtil.endOfDay(yesterday), "yyyy-MM-dd HH:mm:ss"); + } + List reportTokerCalls = reportTokerCallRepository.queryAllByTimeAndManagerId(beginTime, endTime, SecurityUtils.getCurrentUserId()); + // 需要实时查询当天的统计 + if (judgmentDate(DateUtil.parseDate(endTime), DateUtil.parseDate(DateUtil.today()))) { + String statTime = String.valueOf(DateUtil.beginOfDay(DateUtil.date())); + List reportTokerCalls1 = reportSync.reportTalkCallInfo(statTime, endTime, SecurityUtils.getCurrentUserId()); + reportTokerCalls.addAll(reportTokerCalls1); + } + List> maps = new ArrayList<>(); + if (CollUtil.isEmpty(reportTokerCalls)) { + return CommonResponse.createBySuccess(maps); + } + Map callMap = new HashMap<>(); + for (ReportTokerCall reportTokerCall : reportTokerCalls) { + String createTime = DateUtil.format(reportTokerCall.getCreateTime(), "yyyy-MM-dd"); + callMap.put(createTime, reportTokerCall); + } + long betweenDay = DateUtil.between(DateUtil.parseDate(beginTime), DateUtil.parseDate(endTime), DateUnit.DAY); + + for (int i = 0; i <= betweenDay; i++) { + String time = DateUtil.format(DateUtil.offsetDay(DateUtil.parseDate(beginTime), i), "yyyy-MM-dd"); + Map map = new HashMap<>(4); + if (callMap.containsKey(time)) { + ReportTokerCall reportTokerCall = callMap.get(time); + map.put("usrNum", reportTokerCall.getUsrNum()); + map.put("usrNumRate", reportTokerCall.getUsrNumRate()); + map.put("turnOnNum", reportTokerCall.getTurnOnNum()); + map.put("turnOnRate", reportTokerCall.getTurnOnRate()); + map.put("time", time); + } else { + map.put("usrNum", 0); + map.put("usrNumRate", 0.0); + map.put("turnOnNum", 0); + map.put("turnOnRate", 0.0); + map.put("time", time); + } + maps.add(map); + } + return CommonResponse.createBySuccess(maps); + } + @Override public CommonResponse> getReportHomePage(Long userId) { Map map = new HashMap<>(2); @@ -485,7 +533,7 @@ public class ReportTokerServiceImpl implements ReportTokerService { } } //今日实时 - if (clueTalk.getNewestCallTime() != null && judgmentDate(clueTalk.getNewestCallTime(), DateUtil.date())) { + if (clueTalk.getNewestCallTime() != null && judgmentDate(clueTalk.getNewestCallTime(), DateUtil.date())) { if (clueTalk.getClueCallStatus() == DefaultNumberConstants.ONE_NUMBER) { report.setUsrNum(report.getUsrNum() + 1); } else if (clueTalk.getClueCallStatus() == DefaultNumberConstants.TWO_NUMBER) { @@ -517,7 +565,7 @@ public class ReportTokerServiceImpl implements ReportTokerService { return taskSet; } - private Boolean judgmentDate(Date time, Date date) { + private static Boolean judgmentDate(Date time, Date date) { return DateUtil.betweenDay(time, date, true) == DefaultNumberConstants.ZERO_NUMBER; } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/OceanEngineSync.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/OceanEngineSync.java index 9101dc75..36216d9e 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/OceanEngineSync.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/OceanEngineSync.java @@ -45,6 +45,7 @@ public class OceanEngineSync { private final ClueMiddleRepository clueMiddleRepository; @Scheduled(cron = "0 0/15 * * * ?") + @Transactional(rollbackFor = Exception.class) public void getFeiYuSource() { List oceanEngineTokens = oceanEngineClient.queryByStatus(1, SecurityConstants.FROM_IN).getBody(); if (CollUtil.isEmpty(oceanEngineTokens)) { diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java index 8b5bb461..370df03a 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java @@ -1,16 +1,25 @@ package com.baiye.task; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; +import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.SourceLabelConstants; import com.baiye.feign.UserClient; +import com.baiye.model.dto.HomePageReportDTO; +import com.baiye.module.dao.ClueJpa; import com.baiye.module.dao.ClueTalkRepository; +import com.baiye.module.dao.ReportTokerCallRepository; import com.baiye.module.dao.ReportTokerRepository; import com.baiye.module.entity.ClueTalk; import com.baiye.module.entity.ReportToker; +import com.baiye.module.entity.ReportTokerCall; +import com.baiye.module.service.dto.ClueTalkDTO; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; import java.util.*; import java.util.stream.Collectors; @@ -25,12 +34,15 @@ public class ReportSync { private final UserClient userClient; private final ReportTokerRepository reportTokerRepository; private final ClueTalkRepository clueTalkRepository; + private final ClueJpa clueJpa; + private final ReportTokerCallRepository repository; /** * 每天晚上23点,定时统计外呼信息 */ -// @Scheduled(cron = "0 0 0/1 * * ? ") - @Scheduled(cron = "0 0 23 * * ? ") +// @Scheduled(cron = "0 0/5 * * * ? ") + @Scheduled(cron = "0 0 22 * * ? ") + @Transactional(rollbackFor = Exception.class) public void reportToker() { log.info("拓客投流统计 开始------------------{}", DateUtil.date()); //当前时间 @@ -39,6 +51,9 @@ public class ReportSync { List clueTalks = clueTalkRepository.queryClueByLabelTime(beginOfDay, endOfDay); List list = dealData(clueTalks); reportTokerRepository.saveAll(list); + //统计每天呼叫信息 + List reportTokerCalls = reportTalkCallInfo(beginOfDay, endOfDay, null); + repository.saveAll(reportTokerCalls); log.info("拓客投流统计 结束------------------{}", DateUtil.date()); } @@ -90,4 +105,44 @@ public class ReportSync { } return list; } + + public List reportTalkCallInfo(String beginOfDay, String endOfDay, Long managerId) { + List reportCallInfo = clueJpa.getReportCallInfo(beginOfDay, endOfDay, managerId); + List list = new ArrayList<>(); + if (CollUtil.isEmpty(reportCallInfo)) { + return list; + } + Map> talkByManagerId = reportCallInfo.stream().collect(Collectors.groupingBy(ClueTalkDTO::getManagerId, Collectors.toList())); + for (Long key : talkByManagerId.keySet()) { + Integer totalNum = clueTalkRepository.countAllByCreateBy(key); + if (totalNum <= 0) { + break; + } + ReportTokerCall talkReport = new ReportTokerCall().init(); + List clueTalks = talkByManagerId.get(key); + for (ClueTalkDTO clueTalk : clueTalks) { + if (clueTalk.getClueCallStatus() == DefaultNumberConstants.ONE_NUMBER) { + talkReport.setUsrNum(talkReport.getUsrNum() + 1); + } else if (clueTalk.getClueCallStatus() == DefaultNumberConstants.TWO_NUMBER) { + talkReport.setTurnOnNum(talkReport.getTurnOnNum() + 1); + talkReport.setUsrNum(talkReport.getUsrNum() + 1); + } + } + rate(talkReport, totalNum); + talkReport.setManagerId(key); + list.add(talkReport); + } + return list; + } + + private void rate(ReportTokerCall report, Integer totalNum) { + double usrRate; + double turnRate = 0.00; + usrRate = NumberUtil.div(report.getUsrNum(), totalNum, 2).doubleValue(); + if (report.getUsrNum() != DefaultNumberConstants.ZERO_NUMBER) { + turnRate = NumberUtil.div(report.getTurnOnNum(), report.getUsrNum(), 2).doubleValue(); + } + report.setUsrNumRate(usrRate); + report.setTurnOnRate(turnRate); + } } From db637cf894917d0de7ae27c44f973a8112cdc044 Mon Sep 17 00:00:00 2001 From: wujingtao Date: Wed, 15 Feb 2023 10:07:06 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=B2=E7=9F=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/baiye/task/ReportSync.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java index 370df03a..ab6a8240 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java @@ -6,7 +6,6 @@ import cn.hutool.core.util.NumberUtil; import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.SourceLabelConstants; import com.baiye.feign.UserClient; -import com.baiye.model.dto.HomePageReportDTO; import com.baiye.module.dao.ClueJpa; import com.baiye.module.dao.ClueTalkRepository; import com.baiye.module.dao.ReportTokerCallRepository; @@ -60,7 +59,10 @@ public class ReportSync { public List dealData(List clueTalks) { List list = new ArrayList<>(); //按人员id分组 - HashMap> mapByUserId = new HashMap<>(clueTalks.stream().collect(Collectors.groupingBy(ClueTalk::getMemberId, Collectors.toList()))); +// HashMap> mapByUserId = new HashMap<>(clueTalks.stream().collect(Collectors.groupingBy(ClueTalk::getMemberId, Collectors.toList()))); + + HashMap> mapByUserId = new HashMap<>(clueTalks.stream() + .filter(item -> item.getMemberId() != null).collect(Collectors.groupingBy(ClueTalk::getMemberId))); Set userIds = mapByUserId.keySet(); Map userNameList = userClient.findById(userIds); for (Long memberId : mapByUserId.keySet()) { From cf1b12eee677de456a7127deda1a307eb4cb5a5d Mon Sep 17 00:00:00 2001 From: wujingtao Date: Wed, 15 Feb 2023 10:23:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/report/service/impl/QueryReportServiceImpl.java | 4 ++-- .../src/main/java/com/baiye/timed/ReportDeductsSync.java | 6 +++--- .../baiye/module/service/impl/ReportTokerServiceImpl.java | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) 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 653a578d..58062e83 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 @@ -712,8 +712,8 @@ public class QueryReportServiceImpl implements QueryReportService { Map map = new HashMap<>(4); if (callMap.containsKey(time)) { ReportDeduct reportDeduct = callMap.get(time); - map.put("balance", reportDeduct.getBalance()); - map.put("deductAmount", reportDeduct.getDeductAmount()); + map.put("balance", reportDeduct.getBalance() == null ? 0.0 : reportDeduct.getBalance() == null); + map.put("deductAmount", reportDeduct.getDeductAmount() == null ? 0.0 : reportDeduct.getDeductAmount()); } else { map.put("balance", 0); map.put("deductAmount", 0); diff --git a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java index f12fe9fb..8a69e75a 100644 --- a/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java +++ b/ad-platform-manage/ad-platform-management/src/main/java/com/baiye/timed/ReportDeductsSync.java @@ -59,10 +59,10 @@ public class ReportDeductsSync { List callDeducts; if (companyId != null) { callDeducts = callDeductRepository.queryByCompanyIdAndTime(companyId, beginOfDay, endOfDay); - Double sum = callDeducts.stream().mapToDouble(CallDeduct::getDeductAmount).sum(); + double sum = callDeducts.stream().mapToDouble(CallDeduct::getDeductAmount).sum(); ReportDeduct reportDeduct = new ReportDeduct(); reportDeduct.setDeductAmount(sum); - reportDeduct.setBalance(map.get(companyId)); + reportDeduct.setBalance(map.get(companyId) == null ? 0.0 : map.get(companyId)); reportDeduct.setCreateTime(new Date()); reportDeduct.setCompanyId(companyId); list.add(reportDeduct); @@ -71,7 +71,7 @@ public class ReportDeductsSync { Map> collect = callDeducts.stream().collect(Collectors.groupingBy(CallDeduct::getCompanyId, Collectors.toList())); for (Long key : map.keySet()) { ReportDeduct reportDeduct = new ReportDeduct(); - reportDeduct.setBalance(map.get(key)); + reportDeduct.setBalance(map.get(key) == null ? 0.0 : map.get(key)); reportDeduct.setCreateTime(new Date()); reportDeduct.setCompanyId(key); List callDeducts1 = collect.get(key); diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java index c31d50dc..5a86388f 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java @@ -431,14 +431,13 @@ public class ReportTokerServiceImpl implements ReportTokerService { map.put("usrNumRate", reportTokerCall.getUsrNumRate()); map.put("turnOnNum", reportTokerCall.getTurnOnNum()); map.put("turnOnRate", reportTokerCall.getTurnOnRate()); - map.put("time", time); } else { map.put("usrNum", 0); map.put("usrNumRate", 0.0); map.put("turnOnNum", 0); map.put("turnOnRate", 0.0); - map.put("time", time); } + map.put("time", time); maps.add(map); } return CommonResponse.createBySuccess(maps); From 5b28da6fd680224a76dca15a90ae4b9cdb1d8356 Mon Sep 17 00:00:00 2001 From: wujingtao Date: Fri, 17 Feb 2023 15:23:17 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/baiye/module/service/impl/ClueServiceImpl.java | 1 + 1 file changed, 1 insertion(+) 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 b03c1ad0..b7269292 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 @@ -830,6 +830,7 @@ public class ClueServiceImpl implements ClueService { crmTaskId = body.get(0).getId(); crmTotalNumber = body.get(0).getTotalNumber(); } else { + log.error("回流失败的管理员id== {}",clue.getCreateBy()); throw new BadRequestException("回流失败"); } Task crmTask = new Task();