Merge remote-tracking branch 'origin/master'

master
bynt 2 years ago
commit 7711c37dc0

@ -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;

@ -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() {
}
}

@ -28,4 +28,6 @@ public class Company extends BaseCompany implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Transient
private Double deductAmount;
}

@ -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<String, Object> 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<String, Object> 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("激活失败");
}
}
}

@ -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<ActivationRecord, Long>, JpaSpecificationExecutor<ActivationRecord> {
}

@ -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<CallDeduct, Long>, JpaSpecificationExecutor<CallDeduct> {
/**
*
*
* @param companyId
* @param beginTime
* @param endTime
@ -43,10 +44,9 @@ public interface CallDeductRepository extends JpaRepository<CallDeduct, Long>, J
List<CallDeductVO> findByCompanyIdAndTime(Long companyId, Date beginTime, Date endTime);
/**
* id
*
* @param companyId
* @param parse
* @param endDate
@ -54,4 +54,23 @@ public interface CallDeductRepository extends JpaRepository<CallDeduct, Long>, J
*/
@Query(value = "from CallDeduct where companyId = ?1 and createTime >= ?2 and createTime <= ?3")
List<CallDeduct> queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate);
/**
* id
*
* @param parse
* @param endDate
* @return
*/
@Query(value = "from CallDeduct where createTime >= ?1 and createTime <= ?2")
List<CallDeduct> 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);
}

@ -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;
/**
@ -131,4 +132,15 @@ public interface CompanyRepository extends JpaRepository<Company, Long>, 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);
@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<Map<String, Object>> findUserBalanceByUserId(Long companyId);
}

@ -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<Object> generateActivationCode(@RequestParam("codeNum") int codeNum, @RequestParam("codeType") int codeType){
activationCodeService.generateActivationCode(codeNum, codeType);
return CommonResponse.createBySuccess();
}
@ApiOperation("查询(分页)")
@GetMapping("/queryAll")
public ResponseEntity<Object> queryAll(ActivationCodeQueryCriteria activationCodeQueryCriteria, Pageable pageable) {
return new ResponseEntity<>(activationCodeService.queryAll(activationCodeQueryCriteria, pageable), HttpStatus.OK);
}
}

@ -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);
}

@ -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);
}

@ -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;
}

@ -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;

@ -111,4 +111,7 @@ public class CompanyDto extends BaseDTO implements Serializable {
@ApiModelProperty("dmp上传数量")
private Integer dmpLimitNum;
@ApiModelProperty("消费合计")
private Double deductAmount;
}

@ -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<ActivationRecord> 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<ActivationRecord> page = activationCodeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageRequest);
return PageUtil.toPage(page.map(activationCodeMapper::toDto));
}
}

@ -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)
@ -74,6 +77,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));
}
@ -82,6 +86,13 @@ public class CompanyServiceImpl implements CompanyService {
public Map<String, Object> queryAll(CompanyQueryCriteria criteria, Pageable pageable) {
Page<Company> 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());
}
@ -107,6 +118,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));
}

@ -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<String, Object> queryAll(WechatSendMessageQueryCriteria criteria, Pageable pageable) {
@ -148,4 +154,20 @@ public class WechatSendMessageServiceImpl implements WechatSendMessageService {
wechatSendMessageRepository.deleteById(id);
}
/**
* Propagation.REQUIRES_NEW:
* 1/
* 2
* 3service,springTransactionInterceptor,-generateActivationCoderegister(),
* thisregister().
*/
@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);
}
}

@ -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<ActivationCodeDto, ActivationRecord> {
}

@ -102,4 +102,10 @@ public class ReportController {
public void downloadCallRecordDetails(HttpServletResponse response, Long clueId) {
queryReportService.downloadCallRecordDetails(response, clueId);
}
@PostMapping("/report/deduct")
@ApiOperation("统计公司的消费情况")
public CommonResponse<Object> reportDeduct(@RequestBody StatisticalReportDTO statisticalReportDTO) {
return queryReportService.reportDeduct(statisticalReportDTO);
}
}

@ -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<ReportDeduct, Long>, JpaSpecificationExecutor<ReportDeduct> {
/**
* id
*
* @param companyId
* @param parse
* @param endDate
* @return
*/
@Query(value = "from ReportDeduct where companyId = ?1 and createTime >= ?2 and createTime <= ?3")
List<ReportDeduct> queryByCompanyIdAndTime(Long companyId, DateTime parse, DateTime endDate);
}

@ -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() {
}
}

@ -69,4 +69,9 @@ public interface QueryReportService {
* 线
*/
void downloadCallRecordDetails(HttpServletResponse response, Long clueId);
/**
* 线
*/
CommonResponse<Object> reportDeduct(StatisticalReportDTO s);
}

@ -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<Object> 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<ReportDeduct> reportDeducts = reportDeductRepository.queryByCompanyIdAndTime(s.getCompanyId(), beginTime, endTime);
// 需要实时查询当天的统计
if (judgmentDate(endTime, DateUtil.parseDate(DateUtil.today()))) {
DateTime statTime = DateUtil.beginOfDay(DateUtil.date());
List<ReportDeduct> reportDeducts1 = reportDeductsSync.reportDeducts(statTime, endTime, s.getCompanyId());
reportDeducts.addAll(reportDeducts1);
}
List<Map<String, Object>> maps = new ArrayList<>();
if (CollUtil.isEmpty(reportDeducts)) {
return CommonResponse.createBySuccess(maps);
}
Map<String, ReportDeduct> 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<String, Object> map = new HashMap<>(4);
if (callMap.containsKey(time)) {
ReportDeduct reportDeduct = callMap.get(time);
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);
}
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;
}
/**
*
*/

@ -282,6 +282,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
telephoneCallStopDTO.setCallId(requestId);
return CommonResponse.createBySuccess(telephoneCallStopDTO);
}
@Override
public CommonResponse<Object> 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;
}
}
}

@ -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<ReportDeduct> reportDeducts = reportDeducts(DateUtil.parseDateTime(beginOfDay), DateUtil.parseDateTime(endOfDay), null);
repository.saveAll(reportDeducts);
log.info("++++++++++++++++++++++countReport deduct end time {} ++++++++++++++++", DateUtil.now());
}
public List<ReportDeduct> reportDeducts(DateTime beginOfDay, DateTime endOfDay, Long companyId) {
List<Map<String, Object>> userBalances = companyRepository.findUserBalanceByUserId(companyId);
HashMap<Long, Double> map = new HashMap<>();
for (Map<String, Object> map1 : userBalances) {
BigInteger key = (BigInteger) map1.get("id");
Long id = key.longValue();
Double value = (Double) map1.get("userBalance");
map.put(id, value);
}
List<ReportDeduct> list = new ArrayList<>();
List<CallDeduct> 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) == null ? 0.0 : map.get(companyId));
reportDeduct.setCreateTime(new Date());
reportDeduct.setCompanyId(companyId);
list.add(reportDeduct);
} else {
callDeducts = callDeductRepository.queryByCompanyIdAndTime(beginOfDay, endOfDay);
Map<Long, List<CallDeduct>> collect = callDeducts.stream().collect(Collectors.groupingBy(CallDeduct::getCompanyId, Collectors.toList()));
for (Long key : map.keySet()) {
ReportDeduct reportDeduct = new ReportDeduct();
reportDeduct.setBalance(map.get(key) == null ? 0.0 : map.get(key));
reportDeduct.setCreateTime(new Date());
reportDeduct.setCompanyId(key);
List<CallDeduct> 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;
}
}

@ -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<TaskReport> autoCountReportByTask(String beginOfDay, String endOfDay, List<CallClueInfo> callClueInfos) {
//根据任务id分组
HashMap<Long, List<CallClueInfo>> map = new HashMap<>(callClueInfos.stream().collect(Collectors.groupingBy(CallClueInfo::getTaskId, Collectors.toList())));

@ -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_

@ -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_

@ -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;
}

@ -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;
}

@ -168,6 +168,7 @@ public class ClueController {
@ApiOperation("按任务获取当日所有意向数据")
@GetMapping("/countClueByTaskId")
@Inner(value = false)
public CommonResponse<Integer> countClueByTaskId(@RequestParam(value = "taskId") Long taskId,
@RequestParam(value = "beginTime") String beginTime,
@RequestParam(value = "endTime") String endTime) {

@ -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<List<Map<String, Object>>> getReportCallInfo(@RequestParam(value = "beginTime") String beginTime,
@RequestParam(value = "endTime") String endTime
) {
return reportTokerService.getReportCallInfo(beginTime, endTime);
}
}

@ -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<ClueTalkDTO> 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<ClueTalkDTO> 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;
}
}

@ -143,7 +143,7 @@ public interface ClueMiddleRepository extends JpaRepository<ClueMiddle, Long>, 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<Map<String,Object>> findTaskIdCount(Set<Long> taskIds);
List<Map<String, Object>> findTaskIdCount(Set<Long> 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)

@ -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<ClueTalk, Long>, JpaSp
" where tc.create_by = ?1", nativeQuery = true)
List<ClueTalk> 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);
/**
*
*

@ -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<ReportTokerCall, Long>, JpaSpecificationExecutor<ReportTokerCall> {
/**
*
*
* @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<ReportTokerCall> queryAllByTimeAndManagerId(String beginTime, String endTime,Long managerId);
}

@ -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;
}
}

@ -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<Object> reportClueStage(ReportStageAndTurnoverDto reportStageAndTurnoverDto);
CommonResponse<Map<String, HomePageReportDTO>> getReportHomePage(Long userId);
CommonResponse<List<Map<String, Object>>> getReportCallInfo(String beginTime, String endTime);
}

@ -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;
}

@ -829,6 +829,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();

@ -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<Map<String, Object>> reportTokerBroken(ReportTokerDTO reportTokerDTO) {
@ -396,6 +395,54 @@ public class ReportTokerServiceImpl implements ReportTokerService {
return list;
}
@Override
public CommonResponse<List<Map<String, Object>>> 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<ReportTokerCall> 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<ReportTokerCall> reportTokerCalls1 = reportSync.reportTalkCallInfo(statTime, endTime, SecurityUtils.getCurrentUserId());
reportTokerCalls.addAll(reportTokerCalls1);
}
List<Map<String, Object>> maps = new ArrayList<>();
if (CollUtil.isEmpty(reportTokerCalls)) {
return CommonResponse.createBySuccess(maps);
}
Map<String, ReportTokerCall> 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<String, Object> 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());
} 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<Map<String, HomePageReportDTO>> getReportHomePage(Long userId) {
Map<String, HomePageReportDTO> map = new HashMap<>(2);
@ -485,7 +532,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 +564,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;
}
}

@ -45,6 +45,7 @@ public class OceanEngineSync {
private final ClueMiddleRepository clueMiddleRepository;
@Scheduled(cron = "0 0/15 * * * ?")
@Transactional(rollbackFor = Exception.class)
public void getFeiYuSource() {
List<OceanEngineToken> oceanEngineTokens = oceanEngineClient.queryByStatus(1, SecurityConstants.FROM_IN).getBody();
if (CollUtil.isEmpty(oceanEngineTokens)) {

@ -1,16 +1,24 @@
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.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 +33,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,13 +50,19 @@ public class ReportSync {
List<ClueTalk> clueTalks = clueTalkRepository.queryClueByLabelTime(beginOfDay, endOfDay);
List<ReportToker> list = dealData(clueTalks);
reportTokerRepository.saveAll(list);
//统计每天呼叫信息
List<ReportTokerCall> reportTokerCalls = reportTalkCallInfo(beginOfDay, endOfDay, null);
repository.saveAll(reportTokerCalls);
log.info("拓客投流统计 结束------------------{}", DateUtil.date());
}
public List<ReportToker> dealData(List<ClueTalk> clueTalks) {
List<ReportToker> list = new ArrayList<>();
//按人员id分组
HashMap<Long, List<ClueTalk>> mapByUserId = new HashMap<>(clueTalks.stream().collect(Collectors.groupingBy(ClueTalk::getMemberId, Collectors.toList())));
// HashMap<Long, List<ClueTalk>> mapByUserId = new HashMap<>(clueTalks.stream().collect(Collectors.groupingBy(ClueTalk::getMemberId, Collectors.toList())));
HashMap<Long, List<ClueTalk>> mapByUserId = new HashMap<>(clueTalks.stream()
.filter(item -> item.getMemberId() != null).collect(Collectors.groupingBy(ClueTalk::getMemberId)));
Set<Long> userIds = mapByUserId.keySet();
Map<Long, String> userNameList = userClient.findById(userIds);
for (Long memberId : mapByUserId.keySet()) {
@ -90,4 +107,44 @@ public class ReportSync {
}
return list;
}
public List<ReportTokerCall> reportTalkCallInfo(String beginOfDay, String endOfDay, Long managerId) {
List<ClueTalkDTO> reportCallInfo = clueJpa.getReportCallInfo(beginOfDay, endOfDay, managerId);
List<ReportTokerCall> list = new ArrayList<>();
if (CollUtil.isEmpty(reportCallInfo)) {
return list;
}
Map<Long, List<ClueTalkDTO>> 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<ClueTalkDTO> 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);
}
}

Loading…
Cancel
Save