补量代码

master
wjt 1 year ago
parent d1da18d5cf
commit 4473093930

@ -1,6 +1,5 @@
package com.baiye.feign; package com.baiye.feign;
import com.baiye.annotation.Inner;
import com.baiye.feign.callback.SourceClueClientFallback; import com.baiye.feign.callback.SourceClueClientFallback;
import com.baiye.http.CommonResponse; import com.baiye.http.CommonResponse;
import com.baiye.model.dto.ClueQueryCriteria; import com.baiye.model.dto.ClueQueryCriteria;
@ -100,5 +99,10 @@ public interface SourceClueClient {
@ApiOperation("根据组员互换所属组") @ApiOperation("根据组员互换所属组")
@PostMapping(API_PREFIX + "/updateClueOrganize") @PostMapping(API_PREFIX + "/updateClueOrganize")
ResponseEntity<Object> updateClueOrganize(@RequestBody Map<Long, Long> map); ResponseEntity<Object> updateClueOrganize(@RequestBody Map<Long, Long> map);
@ApiOperation("修改拓客和投流线索的冻结状态")
@GetMapping(API_PREFIX + "/updateTalkClueFreeze")
void updateTalkClueFreeze(@RequestParam("clueId") Long clueId, @RequestParam("isFreeze") Boolean isFreeze);
} }

@ -102,4 +102,8 @@ public class SourceClueClientFallback implements SourceClueClient {
public ResponseEntity<Object> updateClueOrganize(Map<Long, Long> map) { public ResponseEntity<Object> updateClueOrganize(Map<Long, Long> map) {
return null; return null;
} }
@Override
public void updateTalkClueFreeze(Long clueId, Boolean isFreeze) {
}
} }

@ -2,6 +2,7 @@ package com.baiye.modules.agent.controller;
import com.baiye.annotation.Inner; import com.baiye.annotation.Inner;
import com.baiye.http.CommonResponse; import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ChannelQuery;
import com.baiye.modules.agent.service.ChannelManageService; import com.baiye.modules.agent.service.ChannelManageService;
import com.baiye.util.SecurityUtils; import com.baiye.util.SecurityUtils;
@ -12,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Set; import java.util.Set;
@ -55,5 +57,10 @@ public class ChannelManageController {
return channelManageService.forbidden(ids); return channelManageService.forbidden(ids);
} }
@ApiOperation("配置开通账号")
@PostMapping("/update")
public CommonResponse<Object> update(@RequestBody @Validated ChannelCustom channelCustom) {
channelManageService.update(channelCustom);
return CommonResponse.createBySuccess();
}
} }

@ -1,7 +1,6 @@
package com.baiye.modules.agent.controller; package com.baiye.modules.agent.controller;
import com.baiye.http.CommonResponse; import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.query.ChannelQuery;
import com.baiye.modules.agent.entity.query.ResourceAssignInfoQuery; import com.baiye.modules.agent.entity.query.ResourceAssignInfoQuery;
import com.baiye.modules.agent.entity.query.ResourceChannelQuery; import com.baiye.modules.agent.entity.query.ResourceChannelQuery;
import com.baiye.modules.agent.service.ChannelResourceAssignService; import com.baiye.modules.agent.service.ChannelResourceAssignService;

@ -76,7 +76,6 @@ public class CustomManageController {
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }
@GetMapping("/report") @GetMapping("/report")
@ApiOperation("统计") @ApiOperation("统计")
public CommonResponse<Object> report() { public CommonResponse<Object> report() {

@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import com.baiye.util.NumUtil; import com.baiye.util.NumUtil;
import com.baiye.valid.AddGroup; import com.baiye.valid.AddGroup;
import com.baiye.valid.UpdateGroup;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@ -27,6 +28,7 @@ public class ChannelCustom implements Serializable {
@Id @Id
@Column(name = "id") @Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@NotNull(message = "修改时id不能为空", groups = {UpdateGroup.class})
private Long id; private Long id;
@ApiModelProperty(value = "系统用户id") @ApiModelProperty(value = "系统用户id")
@ -79,6 +81,22 @@ public class ChannelCustom implements Serializable {
@Column(name = "parent_id") @Column(name = "parent_id")
private Long parentId; private Long parentId;
@ApiModelProperty(value = "创建代理商账号数量")
@Column(name = "channel_limit_num")
private Integer channelLimitNum;
@ApiModelProperty(value = "创建直客账号数量")
@Column(name = "custom_limit_num")
private Integer customLimitNum;
// @ApiModelProperty(value = "总话费")
// @Column(name = "total_phone_bill")
// private Integer totalPhoneBill;
//
// @ApiModelProperty(value = "剩余话费")
// @Column(name = "surplus_phone_bill")
// private Integer surplusPhoneBill;
@ApiModelProperty(value = "子账号") @ApiModelProperty(value = "子账号")
@Transient @Transient
private List<ChannelCustom> children; private List<ChannelCustom> children;
@ -101,6 +119,8 @@ public class ChannelCustom implements Serializable {
this.setType(1); this.setType(1);
this.setTotalNum(0); this.setTotalNum(0);
this.setSurplusNum(0); this.setSurplusNum(0);
// this.setTotalPhoneBill(0);
// this.setSurplusPhoneBill(0);
this.setStatus(1); this.setStatus(1);
this.setActivationCode(null); this.setActivationCode(null);
this.setCreateTime(DateUtil.date()); this.setCreateTime(DateUtil.date());
@ -108,6 +128,8 @@ public class ChannelCustom implements Serializable {
this.setParentId(null); this.setParentId(null);
this.setUserId(userId); this.setUserId(userId);
this.setPhone(phone); this.setPhone(phone);
this.setCustomLimitNum(100);
this.setChannelLimitNum(1);
return this; return this;
} }
@ -116,6 +138,8 @@ public class ChannelCustom implements Serializable {
this.setType(2); this.setType(2);
this.setTotalNum(0); this.setTotalNum(0);
this.setSurplusNum(0); this.setSurplusNum(0);
// this.setTotalPhoneBill(0);
// this.setSurplusPhoneBill(0);
this.setStatus(1); this.setStatus(1);
String activeCode = "by" + NumUtil.getFourNum(parentId.intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4); String activeCode = "by" + NumUtil.getFourNum(parentId.intValue()) + DateUtil.format(DateUtil.date(), "MMdd") + RandomUtil.randomString(4);
this.setActivationCode(activeCode); this.setActivationCode(activeCode);

@ -44,6 +44,16 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
@Query("select c from ChannelCustom c where c.parentId = ?1") @Query("select c from ChannelCustom c where c.parentId = ?1")
List<ChannelCustom> findByParentId(Long parentId); List<ChannelCustom> findByParentId(Long parentId);
/**
*
*
* @param parentId
* @param type
* @return
*/
@Query(value = "select count(*) from tb_channel_custom where parent_id = ?1 and type = ?2", nativeQuery = true)
Integer countByParentIdAndType(Long parentId, Integer type);
/** /**
* *
* *
@ -112,6 +122,16 @@ public interface ChannelCustomRepository extends JpaRepository<ChannelCustom, Lo
@Query("UPDATE ChannelCustom set surplusNum = surplusNum - ?2 where userId = ?1") @Query("UPDATE ChannelCustom set surplusNum = surplusNum - ?2 where userId = ?1")
void updateQuantity(Long userId, Integer number); void updateQuantity(Long userId, Integer number);
/**
*
*
* @param userId
* @param number
*/
@Modifying
@Query("UPDATE ChannelCustom set surplusNum = surplusNum + ?2 where userId = ?1")
void updateSurplusNumByUserId(Long userId, Integer number);
/** /**
* *
* *

@ -1,6 +1,7 @@
package com.baiye.modules.agent.service; package com.baiye.modules.agent.service;
import com.baiye.http.CommonResponse; import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ChannelQuery;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -36,6 +37,7 @@ public interface ChannelManageService {
* @return * @return
*/ */
CommonResponse<Object> report(); CommonResponse<Object> report();
/** /**
* *
* *
@ -51,4 +53,11 @@ public interface ChannelManageService {
* @return * @return
*/ */
CommonResponse<Object> forbidden(Set<Long> ids); CommonResponse<Object> forbidden(Set<Long> ids);
/**
*
*
* @param channelCustom
*/
void update(ChannelCustom channelCustom);
} }

@ -4,7 +4,6 @@ import com.baiye.http.CommonResponse;
import com.baiye.modules.agent.entity.ChannelCustom; import com.baiye.modules.agent.entity.ChannelCustom;
import com.baiye.modules.agent.entity.query.ChannelQuery; import com.baiye.modules.agent.entity.query.ChannelQuery;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

@ -144,9 +144,11 @@ public class ChannelManageServiceImpl implements ChannelManageService {
if (channelCustom.getType() == 1) { if (channelCustom.getType() == 1) {
continue; continue;
} }
//返回量
int num = channelCustom.getSurplusNum(); int num = channelCustom.getSurplusNum();
channelCustom.setStatus(3); channelCustom.setStatus(3);
channelCustom.setSurplusNum(0); channelCustom.setSurplusNum(0);
//返回话费
list.add(channelCustom); list.add(channelCustom);
if (channelCustom.getParentId() != null) { if (channelCustom.getParentId() != null) {
channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num); channelCustomRepository.updateSurplusNum(channelCustom.getParentId(), num);
@ -161,6 +163,18 @@ public class ChannelManageServiceImpl implements ChannelManageService {
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }
@Override
public void update(ChannelCustom channelCustom) {
ChannelCustom channelCustomNew = channelCustomRepository.findById(channelCustom.getId()).orElseGet(ChannelCustom::new);
if (channelCustom.getChannelLimitNum() != null) {
channelCustomNew.setChannelLimitNum(channelCustom.getChannelLimitNum());
}
if (channelCustom.getCustomLimitNum() != null) {
channelCustomNew.setCustomLimitNum(channelCustom.getCustomLimitNum());
}
channelCustomRepository.save(channelCustomNew);
}
/** /**
* *
* *

@ -72,6 +72,16 @@ public class CustomManageServiceImpl implements CustomManageService {
if (ObjectUtil.isNotEmpty(byAndChannelName)) { if (ObjectUtil.isNotEmpty(byAndChannelName)) {
return CommonResponse.createByErrorMessage("名称重复"); return CommonResponse.createByErrorMessage("名称重复");
} }
//获取父账号信息
ChannelCustom parent = getChannelCustomByUserId();
//验证开通数量
Integer limitNum = channelCustomRepository.countByParentIdAndType(parent.getId(), channelCustom.getType());
if (channelCustom.getType() == 1 && parent.getChannelLimitNum() <= limitNum) {
return CommonResponse.createByErrorMessage("最多创建渠道商" + parent.getChannelLimitNum() + "个");
}
if (channelCustom.getType() == 2 && parent.getCustomLimitNum() <= limitNum) {
return CommonResponse.createByErrorMessage("最多创建直客" + parent.getCustomLimitNum() + "个");
}
if (!MobileUtil.checkPhone(channelCustom.getPhone())) { if (!MobileUtil.checkPhone(channelCustom.getPhone())) {
return CommonResponse.createByErrorMessage(ResponseCode.PHONE_NUMBER_IS_INCORRECT.getDesc()); return CommonResponse.createByErrorMessage(ResponseCode.PHONE_NUMBER_IS_INCORRECT.getDesc());
} }
@ -81,8 +91,7 @@ public class CustomManageServiceImpl implements CustomManageService {
} }
//新建账号状态为2 待开通 //新建账号状态为2 待开通
channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER); channelCustom.setStatus(DefaultNumberConstants.TWO_NUMBER);
//获取父账号的总量
ChannelCustom parent = getChannelCustomByUserId();
//设置分配 //设置分配
if (channelCustom.getTotalNum() != null && channelCustom.getTotalNum() > 0) { if (channelCustom.getTotalNum() != null && channelCustom.getTotalNum() > 0) {
// if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) { // if (channelCustom.getType() == DefaultNumberConstants.ONE_NUMBER) {
@ -129,6 +138,8 @@ public class CustomManageServiceImpl implements CustomManageService {
Long userId = create(user).getId(); Long userId = create(user).getId();
channelCustom.setUserId(userId); channelCustom.setUserId(userId);
channelCustom.setStatus(1); channelCustom.setStatus(1);
channelCustom.setChannelLimitNum(1);
channelCustom.setCustomLimitNum(100);
} }
channelCustom.setCreateTime(DateUtil.date()); channelCustom.setCreateTime(DateUtil.date());
channelCustomRepository.save(channelCustom); channelCustomRepository.save(channelCustom);

@ -41,6 +41,9 @@ public class ExcellentCases implements Serializable {
@Column(name = "create_by") @Column(name = "create_by")
private Long createBy; private Long createBy;
@Column(name = "create_name")
private String createName;
@Column(name = "operate_id") @Column(name = "operate_id")
@ApiModelProperty(value = "拨打人id") @ApiModelProperty(value = "拨打人id")
private Long operateId; private Long operateId;

@ -9,4 +9,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2023/5/11 * @date 2023/5/11
*/ */
public interface ExcellentCasesRepository extends JpaRepository<ExcellentCases, Long>, JpaSpecificationExecutor<ExcellentCases> { public interface ExcellentCasesRepository extends JpaRepository<ExcellentCases, Long>, JpaSpecificationExecutor<ExcellentCases> {
ExcellentCases findBySessionId(String sessionId);
} }

@ -112,5 +112,14 @@ public interface OrganizeUserRepository extends JpaRepository<OrganizeUser, Long
@Query(value = "update tb_organize_user set create_by = ?1 where create_by = ?2", nativeQuery = true) @Query(value = "update tb_organize_user set create_by = ?1 where create_by = ?2", nativeQuery = true)
void updateCreateBy(Long replaceUserId, Long userId); void updateCreateBy(Long replaceUserId, Long userId);
List<OrganizeUser> findByCreateByOrUserId(Long createBy,Long userId); List<OrganizeUser> findByCreateByOrUserId(Long createBy, Long userId);
/**
* id
*
* @param userId
* @return
*/
@Query(value = "select ou.user_id from tb_organize_user as ou where ou.organize_id =(select u.organize_id from tb_organize_user as u where u.user_id =?1) and ou.is_leader =true", nativeQuery = true)
Long findUserIdAndIsLeader(Long userId);
} }

@ -12,5 +12,5 @@ import java.util.List;
*/ */
public interface ScriptOrganizeRepository extends JpaRepository<ScriptOrganize, Long>, JpaSpecificationExecutor<ScriptOrganize> { public interface ScriptOrganizeRepository extends JpaRepository<ScriptOrganize, Long>, JpaSpecificationExecutor<ScriptOrganize> {
List<ScriptOrganize> findByCreateBy(Long userId); List<ScriptOrganize> findByCreateByAndStatus(Long userId, Boolean status);
} }

@ -30,8 +30,20 @@ public class ExcellentCasesController {
return CommonResponse.createBySuccess(); return CommonResponse.createBySuccess();
} }
@DeleteMapping("/delete/{id}")
@ApiOperation("删除")
public CommonResponse<Object> delete(@PathVariable("id") Long id) {
excellentCasesService.delete(id);
return CommonResponse.createBySuccess();
}
@GetMapping("/queryAll") @GetMapping("/queryAll")
public ResponseEntity<Object> query(ExcellentCasesQueryCriteria excellentCasesQueryCriteria, Pageable pageable) { public ResponseEntity<Object> query(ExcellentCasesQueryCriteria excellentCasesQueryCriteria, Pageable pageable) {
return new ResponseEntity<>(excellentCasesService.queryAll(excellentCasesQueryCriteria, pageable), HttpStatus.OK); return new ResponseEntity<>(excellentCasesService.queryAll(excellentCasesQueryCriteria, pageable), HttpStatus.OK);
} }
@GetMapping("/querySession")
public CommonResponse<Object> queryBySessionId(@RequestParam("sessionId") String sessionId) {
return CommonResponse.createBySuccess(excellentCasesService.queryBySessionId(sessionId));
}
} }

@ -13,4 +13,8 @@ public interface ExcellentCasesService {
void addExcellentCases(ExcellentCases excellentCases); void addExcellentCases(ExcellentCases excellentCases);
Object queryAll(ExcellentCasesQueryCriteria excellentCasesQueryCriteria, Pageable pageable); Object queryAll(ExcellentCasesQueryCriteria excellentCasesQueryCriteria, Pageable pageable);
void delete(Long id);
ExcellentCases queryBySessionId(String sessionId);
} }

@ -16,6 +16,5 @@ public class ExcellentCasesQueryCriteria {
private String operateName; private String operateName;
@Query(type = Query.Type.EQUAL) @Query(type = Query.Type.EQUAL)
@NotNull(message = "组长id不能为空")
private Long createBy; private Long createBy;
} }

@ -176,6 +176,7 @@ public class CompanyServiceImpl implements CompanyService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CacheEvict(cacheNames = "companyCache", key = "#companyId")
public int updateBalanceOptimistic(Double deduct, Long companyId, Integer version) { public int updateBalanceOptimistic(Double deduct, Long companyId, Integer version) {
return companyRepository.updateBalanceOptimistic(deduct, companyId, version); return companyRepository.updateBalanceOptimistic(deduct, companyId, version);
} }

@ -1,6 +1,7 @@
package com.baiye.modules.platform.service.impl; package com.baiye.modules.platform.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil; import cn.hutool.core.util.URLUtil;
@ -8,6 +9,7 @@ import com.baiye.config.properties.FileProperties;
import com.baiye.exception.BadRequestException; import com.baiye.exception.BadRequestException;
import com.baiye.modules.platform.domain.ExcellentCases; import com.baiye.modules.platform.domain.ExcellentCases;
import com.baiye.modules.platform.repository.ExcellentCasesRepository; import com.baiye.modules.platform.repository.ExcellentCasesRepository;
import com.baiye.modules.platform.repository.OrganizeUserRepository;
import com.baiye.modules.platform.service.ExcellentCasesService; import com.baiye.modules.platform.service.ExcellentCasesService;
import com.baiye.modules.platform.service.dto.ExcellentCasesQueryCriteria; import com.baiye.modules.platform.service.dto.ExcellentCasesQueryCriteria;
import com.baiye.util.PageUtil; import com.baiye.util.PageUtil;
@ -35,13 +37,23 @@ public class ExcellentCasesServiceImpl implements ExcellentCasesService {
private final ExcellentCasesRepository excellentCasesRepository; private final ExcellentCasesRepository excellentCasesRepository;
private final OrganizeUserRepository organizeUserRepository;
private final FileProperties fileProperties; private final FileProperties fileProperties;
@Override @Override
public void addExcellentCases(ExcellentCases excellentCases) { public void addExcellentCases(ExcellentCases excellentCases) {
String sessionId = excellentCases.getSessionId();
ExcellentCases bySessionId = excellentCasesRepository.findBySessionId(sessionId);
if (ObjectUtil.isNotEmpty(bySessionId)) {
if (excellentCases.getRemark() != null) {
bySessionId.setRemark(excellentCases.getRemark());
excellentCasesRepository.save(bySessionId);
return;
}
}
excellentCases.setCreateBy(SecurityUtils.getCurrentUserId()); excellentCases.setCreateBy(SecurityUtils.getCurrentUserId());
excellentCases.setCreateTime(DateUtil.date()); excellentCases.setCreateTime(DateUtil.date());
excellentCases.setCreateName(SecurityUtils.getCurrentUsername());
URL url1 = URLUtil.url(excellentCases.getUrl()); URL url1 = URLUtil.url(excellentCases.getUrl());
BufferedInputStream inputStream; BufferedInputStream inputStream;
String url; String url;
@ -81,11 +93,20 @@ public class ExcellentCasesServiceImpl implements ExcellentCasesService {
@Override @Override
public Object queryAll(ExcellentCasesQueryCriteria excellentCasesQueryCriteria, Pageable pageable) { public Object queryAll(ExcellentCasesQueryCriteria excellentCasesQueryCriteria, Pageable pageable) {
if (excellentCasesQueryCriteria.getCreateBy() == null) { Long userIdAndIsLeader = organizeUserRepository.findUserIdAndIsLeader(SecurityUtils.getCurrentUserId());
throw new BadRequestException("组长id不能为空"); excellentCasesQueryCriteria.setCreateBy(userIdAndIsLeader);
}
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime")); PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime"));
Page<ExcellentCases> all = excellentCasesRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, excellentCasesQueryCriteria, criteriaBuilder), pageRequest); Page<ExcellentCases> all = excellentCasesRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, excellentCasesQueryCriteria, criteriaBuilder), pageRequest);
return PageUtil.toPage(all); return PageUtil.toPage(all);
} }
@Override
public void delete(Long id) {
excellentCasesRepository.deleteById(id);
}
@Override
public ExcellentCases queryBySessionId(String sessionId) {
return excellentCasesRepository.findBySessionId(sessionId);
}
} }

@ -95,6 +95,6 @@ public class ScriptOrganizeServiceImpl implements ScriptOrganizeService {
@Override @Override
public List<ScriptOrganize> queryOrganize(Long userId) { public List<ScriptOrganize> queryOrganize(Long userId) {
return scriptOrganizeRepository.findByCreateBy(userId); return scriptOrganizeRepository.findByCreateByAndStatus(userId, true);
} }
} }

@ -0,0 +1,39 @@
package com.baiye.modules.telemarkting.api;
import com.baiye.http.CommonResponse;
import com.baiye.modules.telemarkting.entity.dto.ClueBoostQueryCriteria;
import com.baiye.modules.telemarkting.service.ClueBoostService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
/**
* @author wjt
* @date 2023/5/16
*/
@Slf4j
@RestController
@RequestMapping("/api/boost")
@RequiredArgsConstructor
public class ClueBoostController {
private final ClueBoostService clueBoostService;
@GetMapping("/queryAll")
public ResponseEntity<Object> query(ClueBoostQueryCriteria clueBoostQueryCriteria, Pageable pageable) {
return new ResponseEntity<>(clueBoostService.queryAll(clueBoostQueryCriteria, pageable), HttpStatus.OK);
}
@ApiOperation("赔付")
@PostMapping("/compensate")
public CommonResponse<Object> compensate(@RequestBody Set<Long> ids) {
clueBoostService.compensate(ids);
return CommonResponse.createBySuccess();
}
}

@ -2,7 +2,6 @@ package com.baiye.modules.telemarkting.api;
import com.baiye.annotation.Inner; import com.baiye.annotation.Inner;
import com.baiye.http.CommonResponse; import com.baiye.http.CommonResponse;
import com.baiye.modules.telemarkting.entity.ExtensionNumber;
import com.baiye.modules.telemarkting.entity.dto.ExtensionNumberCriteria; import com.baiye.modules.telemarkting.entity.dto.ExtensionNumberCriteria;
import com.baiye.modules.telemarkting.service.ExtensionNumberService; import com.baiye.modules.telemarkting.service.ExtensionNumberService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -15,7 +14,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.Map;
/** /**
* @author wujingtao * @author wujingtao

@ -0,0 +1,12 @@
package com.baiye.modules.telemarkting.dao;
import com.baiye.modules.telemarkting.entity.ClueBoostRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author wjt
* @date 2023/5/17
*/
public interface ClueBoostRecordRepository extends JpaRepository<ClueBoostRecord, Long>, JpaSpecificationExecutor<ClueBoostRecord> {
}

@ -0,0 +1,20 @@
package com.baiye.modules.telemarkting.dao;
import com.baiye.modules.telemarkting.entity.ClueBoost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import java.util.Set;
/**
* @author wjt
* @date 2023/5/17
*/
public interface ClueBoostRepository extends JpaRepository<ClueBoost, Long>, JpaSpecificationExecutor<ClueBoost> {
@Modifying
@Query("UPDATE ClueBoost set status = ?1 where id in ?2")
Integer updateStatusByIds(Boolean status, Set<Long> ids);
}

@ -0,0 +1,62 @@
package com.baiye.modules.telemarkting.entity;
import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
/**
* @author wjt
* @date 2023/5/16
*/
@Getter
@Setter
@Entity
@Table(name = "tb_clue_boost")
@EntityListeners(AuditingEntityListener.class)
public class ClueBoost {
@Id
@ApiModelProperty(value = "主键id自动递增")
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "clue_id")
@ApiModelProperty(value = "线索id")
private Long clueId;
@Column(name = "member_id")
@ApiModelProperty(value = "所属人id")
private Long memberId;
@Column(name = "clue_type")
@ApiModelProperty(value = " 类型 1-表单推送 2-个人上传 3-抖音 4-投流 5-拓客 6-拓客回流 7-投流回流")
private Integer clueType;
@Column(name = "which_user_id")
@ApiModelProperty(value = "管理员id")
private Long whichUserId;
@Column(name = "status")
@ApiModelProperty(value = "是否赔付")
private Boolean status;
@Column(name = "create_time")
@ApiModelProperty(value = "创建时间")
private Date createTime;
public ClueBoost addClueBoost(Long clueId, Long memberId, Integer clueType, Long whichUserId) {
this.setClueId(clueId);
this.setMemberId(memberId);
this.setClueType(clueType);
this.setCreateTime(DateUtil.date());
this.setWhichUserId(whichUserId);
this.setStatus(false);
return this;
}
}

@ -0,0 +1,34 @@
package com.baiye.modules.telemarkting.entity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
/**
* @author wjt
* @date 2023/5/17
*/
@Getter
@Setter
@Entity
@Table(name = "tb_clue_boost_record")
@EntityListeners(AuditingEntityListener.class)
public class ClueBoostRecord {
@Id
@ApiModelProperty(value = "主键id自动递增")
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "which_user_id")
@ApiModelProperty(value = "线索id")
private Long whichUserId;
@Column(name = "create_time")
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

@ -0,0 +1,48 @@
package com.baiye.modules.telemarkting.entity.dto;
import lombok.Data;
import java.util.Date;
/**
* @author wjt
* @date 2023/5/16
*/
@Data
public class ClueBoostDTO {
/**
* 线id
*/
private Long clueId;
/**
*
*/
private Integer callNum;
/**
*
*/
private Date firstTime;
/**
*
*/
private Date lastTime;
private Long memberId;
private Integer clueType;
/**
* true false
*/
private Boolean status;
public ClueBoostDTO addClueBoostDTO(Long clueId, Long memberId, Integer clueType, Boolean status) {
this.setClueId(clueId);
this.setMemberId(memberId);
this.setClueType(clueType);
this.setStatus(status);
return this;
}
}

@ -0,0 +1,26 @@
package com.baiye.modules.telemarkting.entity.dto;
import com.baiye.annotation.Query;
import lombok.Data;
import java.sql.Timestamp;
import java.util.List;
/**
* @author wjt
* @date 2023/5/17
*/
@Data
public class ClueBoostQueryCriteria {
@Query
private Boolean status = false;
@Query
private Long whichUserId;
@Query
private Integer clueType;
@Query(type = Query.Type.BETWEEN)
private List<Timestamp> createTime;
}

@ -0,0 +1,17 @@
package com.baiye.modules.telemarkting.service;
import com.baiye.modules.telemarkting.entity.dto.ClueBoostQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Set;
/**
* @author wjt
* @date 2023/5/16
*/
public interface ClueBoostService {
Object queryAll(ClueBoostQueryCriteria clueBoostQueryCriteria, Pageable pageable);
void compensate(Set<Long> ids);
}

@ -7,7 +7,6 @@ import com.baiye.modules.telemarkting.entity.ExtensionNumber;
import com.baiye.modules.telemarkting.entity.dto.ExtensionNumberCriteria; import com.baiye.modules.telemarkting.entity.dto.ExtensionNumberCriteria;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
/** /**

@ -0,0 +1,131 @@
package com.baiye.modules.telemarkting.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baiye.feign.SourceClueClient;
import com.baiye.model.dto.UserDto;
import com.baiye.modules.agent.repository.ChannelCustomRepository;
import com.baiye.modules.system.domain.User;
import com.baiye.modules.system.repository.UserRepository;
import com.baiye.modules.telemarkting.dao.ClueBoostRecordRepository;
import com.baiye.modules.telemarkting.dao.ClueBoostRepository;
import com.baiye.modules.telemarkting.entity.ClueBoost;
import com.baiye.modules.telemarkting.entity.ClueBoostRecord;
import com.baiye.modules.telemarkting.entity.dto.ClueBoostDTO;
import com.baiye.modules.telemarkting.entity.dto.ClueBoostQueryCriteria;
import com.baiye.modules.telemarkting.service.ClueBoostService;
import com.baiye.util.PageUtil;
import com.baiye.util.QueryHelp;
import com.baiye.util.RedisUtils;
import com.baiye.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
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 javax.annotation.Resource;
import java.util.Date;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* @author wjt
* @date 2023/5/16
* 线
*/
@Service
@Slf4j
public class ClueBoostServiceImpl implements ClueBoostService {
private static final String KEY = "boost:";
@Resource
private RedisUtils redisUtils;
@Resource
private ClueBoostRepository clueBoostRepository;
@Resource
private SourceClueClient sourceClueClient;
@Resource
private ChannelCustomRepository channelCustomRepository;
@Resource
private ClueBoostRecordRepository clueBoostRecordRepository;
@Resource
private UserRepository userRepository;
@Override
public Object queryAll(ClueBoostQueryCriteria clueBoostQueryCriteria, Pageable pageable) {
clueBoostQueryCriteria.setWhichUserId(SecurityUtils.getCurrentUserId());
PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by(Sort.Direction.DESC, "createTime"));
Page<ClueBoost> all = clueBoostRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, clueBoostQueryCriteria, criteriaBuilder), pageRequest);
return PageUtil.toPage(all);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void compensate(Set<Long> ids) {
Integer integer = clueBoostRepository.updateStatusByIds(true, ids);
Long currentUserId = SecurityUtils.getCurrentUserId();
channelCustomRepository.updateSurplusNumByUserId(currentUserId, integer);
ClueBoostRecord clueBoostRecord = new ClueBoostRecord();
clueBoostRecord.setWhichUserId(currentUserId);
clueBoostRecord.setCreateTime(DateUtil.date());
clueBoostRecordRepository.save(clueBoostRecord);
}
@EventListener(ClueBoostDTO.class)
@Transactional(rollbackFor = Exception.class)
public void boost(ClueBoostDTO clueBoostDTO) {
Object o = redisUtils.get(KEY + clueBoostDTO.getClueId());
if (ObjectUtil.isNotEmpty(o)) {
if (clueBoostDTO.getStatus()) {
redisUtils.del(KEY + clueBoostDTO.getClueId());
return;
}
//redis数据
ClueBoostDTO clueBoost = BeanUtil.toBean(o, ClueBoostDTO.class);
//上一次拨打距离当前时间间隔1小时
Date lastTime = clueBoost.getLastTime();
long betweenLast = DateUtil.between(lastTime, DateUtil.date(), DateUnit.HOUR);
if (betweenLast < 1) {
return;
}
//第一次拨打后 24小时内需2通
Date firstTime = clueBoost.getFirstTime();
long betweenFirst = DateUtil.between(firstTime, DateUtil.date(), DateUnit.HOUR);
Integer callNum = clueBoost.getCallNum();
if (betweenFirst <= 24) {
clueBoost.setCallNum(callNum + 1);
clueBoost.setLastTime(DateUtil.date());
redisUtils.set(KEY + clueBoostDTO.getClueId(), clueBoost, 48 - betweenFirst, TimeUnit.HOURS);
return;
} else if (betweenFirst < 48) {
if (callNum >= 2) {
//满足补量
User user = userRepository.findById(clueBoost.getMemberId()).orElseGet(User::new);
Long whichUserId = user.getWhichUserId();
ClueBoost clueBoostNew = new ClueBoost().addClueBoost(clueBoost.getClueId(), clueBoost.getMemberId(), clueBoost.getClueType(), whichUserId);
// 修改线索为冻结
sourceClueClient.updateTalkClueFreeze(clueBoost.getClueId(), true);
clueBoostRepository.save(clueBoostNew);
redisUtils.del(KEY + clueBoostDTO.getClueId());
return;
}
}
}
if (!clueBoostDTO.getStatus()) {
clueBoostDTO.setLastTime(DateUtil.date());
clueBoostDTO.setFirstTime(DateUtil.date());
clueBoostDTO.setCallNum(1);
redisUtils.set(KEY + clueBoostDTO.getClueId(), clueBoostDTO, 24, TimeUnit.HOURS);
}
}
}

@ -6,6 +6,7 @@ import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baiye.constant.ClueTypeConstants;
import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.DefaultNumberConstants;
import com.baiye.exception.BadRequestException; import com.baiye.exception.BadRequestException;
import com.baiye.feign.SourceClueClient; import com.baiye.feign.SourceClueClient;
@ -25,11 +26,13 @@ import com.baiye.modules.telemarkting.httpRequest.DoubleCallReq;
import com.baiye.modules.telemarkting.httpRequest.RollCallReq; import com.baiye.modules.telemarkting.httpRequest.RollCallReq;
import com.baiye.modules.telemarkting.service.TelephoneCallService; import com.baiye.modules.telemarkting.service.TelephoneCallService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -64,6 +67,8 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
private CallDeductRepository callDeductRepository; private CallDeductRepository callDeductRepository;
@Resource @Resource
private UserService userService; private UserService userService;
@Resource
private ApplicationContext applicationContext;
@Override @Override
public CommonResponse<TelephoneCallStopDTO> doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) { public CommonResponse<TelephoneCallStopDTO> doubleCallReq(TelephoneCallReqDTO doubleCallReq, Long companyId) {
@ -121,7 +126,6 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
allCallInfoRepository.save(allCallInfo); allCallInfoRepository.save(allCallInfo);
//实时扣费 //实时扣费
callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), allCallInfo.getDuration(), DefaultNumberConstants.TWO_NUMBER); callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), allCallInfo.getDuration(), DefaultNumberConstants.TWO_NUMBER);
//更新资源通话状态 //更新资源通话状态
CompletableFuture.runAsync(() -> updateSourceCallStatus(userDate, DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType())); CompletableFuture.runAsync(() -> updateSourceCallStatus(userDate, DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType()));
} else { } else {
@ -269,6 +273,7 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
allCallInfoRepository.updateByRecord(DefaultNumberConstants.ONE_NUMBER, rollCallBackDTO.getRecord_file_url(), allCallInfo.getId()); allCallInfoRepository.updateByRecord(DefaultNumberConstants.ONE_NUMBER, rollCallBackDTO.getRecord_file_url(), allCallInfo.getId());
} else { } else {
log.info("被叫回调-点呼otherLeg:{},详情:{}", otherLeg, rollCallBackDTO); log.info("被叫回调-点呼otherLeg:{},详情:{}", otherLeg, rollCallBackDTO);
boolean status;
//拨打线索号的回调 //拨打线索号的回调
if (StrUtil.isNotBlank(rollCallBackDTO.getCallee_answer_time())) { if (StrUtil.isNotBlank(rollCallBackDTO.getCallee_answer_time())) {
//表示接通,更新线索状态 //表示接通,更新线索状态
@ -278,9 +283,16 @@ public class TelephoneCallServiceImpl implements TelephoneCallService {
CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType())); CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.TWO_NUMBER, allCallInfo.getClueType()));
//实时扣除话费 //实时扣除话费
callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2); callCostCount(allCallInfo.getMemberId(), allCallInfo.getClueId(), allCallInfo.getClueType(), Integer.valueOf(rollCallBackDTO.getDuration()), 2);
status = true;
} else { } else {
//更新资源通话状态 //更新资源通话状态
CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.ONE_NUMBER, allCallInfo.getClueType())); CompletableFuture.runAsync(() -> updateSourceCallStatus(allCallInfo.getClueId(), DefaultNumberConstants.ONE_NUMBER, allCallInfo.getClueType()));
status = false;
}
if (Arrays.asList(ClueTypeConstants.TOKER_TYPE).contains(allCallInfo.getClueType())) {
ClueBoostDTO clueBoostDTO = new ClueBoostDTO().addClueBoostDTO(allCallInfo.getClueId(), allCallInfo.getMemberId(), allCallInfo.getClueType(), null);
clueBoostDTO.setStatus(status);
applicationContext.publishEvent(clueBoostDTO);
} }
} }
} }

@ -94,7 +94,7 @@ public class DeliveryBalanceTask {
// 判断剩余数量 // 判断剩余数量
if (ObjectUtil.isNull(channelCustom.getSurplusNum()) || ObjectUtil.isNull(dmpLimitNum) if (ObjectUtil.isNull(channelCustom.getSurplusNum()) || ObjectUtil.isNull(dmpLimitNum)
|| channelCustom.getSurplusNum() - (number != null ? number : DefaultNumberConstants.ZERO_NUMBER) >> || channelCustom.getSurplusNum() - (number != null ? number : DefaultNumberConstants.ZERO_NUMBER) >>
DefaultNumberConstants.ONE_NUMBER < DefaultNumberConstants.ZERO_NUMBER) { DefaultNumberConstants.ONE_NUMBER < DefaultNumberConstants.TEN_NUMBER) {
continue; continue;
} }
lock.lock(); lock.lock();
@ -109,6 +109,13 @@ public class DeliveryBalanceTask {
list = CollUtil.sub(list, DefaultNumberConstants.ZERO_NUMBER, list = CollUtil.sub(list, DefaultNumberConstants.ZERO_NUMBER,
count >= dmpLimitNum ? DefaultNumberConstants.ZERO_NUMBER : dmpLimitNum); count >= dmpLimitNum ? DefaultNumberConstants.ZERO_NUMBER : dmpLimitNum);
} }
// 最大数量不能大于剩余数量
if (list.size() >= channelCustom.getSurplusNum()) {
list = CollUtil.sub(list, DefaultNumberConstants.ZERO_NUMBER,
channelCustom.getSurplusNum());
downList.addAll(CollUtil.sub
(list, channelCustom.getSurplusNum(), list.size()));
}
if (CollUtil.isNotEmpty(list)) { if (CollUtil.isNotEmpty(list)) {
// 每次100000 数据 // 每次100000 数据
List<List<TaskImei>> lists = Lists.partition List<List<TaskImei>> lists = Lists.partition

@ -127,4 +127,6 @@ public class ClueDto implements Serializable {
private String castInfo; private String castInfo;
@ApiModelProperty(value = "线索是否加密 0:不加密 1:加密") @ApiModelProperty(value = "线索是否加密 0:不加密 1:加密")
private Integer isEncryption; private Integer isEncryption;
@ApiModelProperty(value = "线索是否冻结 0:未冻结 1:冻结")
private Boolean isFreeze;
} }

@ -202,4 +202,11 @@ public class ClueController {
public ResponseEntity<Object> updateClueOrganize(@RequestBody Map<Long, Long> map) { public ResponseEntity<Object> updateClueOrganize(@RequestBody Map<Long, Long> map) {
return new ResponseEntity<>(clueService.updateClueOrganize(map), HttpStatus.OK); return new ResponseEntity<>(clueService.updateClueOrganize(map), HttpStatus.OK);
} }
@ApiOperation("修改拓客和投流线索的冻结状态")
@GetMapping("/updateTalkClueFreeze")
@Inner(value = false)
public void updateTalkClueFreeze(@RequestParam("clueId") Long clueId, @RequestParam("isFreeze") Boolean isFreeze) {
clueService.updateTalkClueFreeze(clueId, isFreeze);
}
} }

@ -17,4 +17,7 @@ import java.util.Set;
@Repository @Repository
public interface AllCallInfoRepository extends JpaRepository<AllCallInfo, Long>, JpaSpecificationExecutor<AllCallInfo> { public interface AllCallInfoRepository extends JpaRepository<AllCallInfo, Long>, JpaSpecificationExecutor<AllCallInfo> {
void deleteAllByClueIdIn(Set<Long> clueIds); void deleteAllByClueIdIn(Set<Long> clueIds);
@Query(value = "select DISTINCT(clue_id) from tb_call_info where status =?1 and (create_time between ?2 and ?3) and clue_id in ?4", nativeQuery = true)
List<Long> findTurnOnClue(Integer status, String beginTime, String endTime, List<Long> clueIds);
} }

@ -73,7 +73,7 @@ public class ClueJpa {
sql.append("select c.id as id,c.name as name,c.nid as nid,c.wx as wx,c.origin as origin,c.collect_time as collectTime,c.address as address,c.record_id as recordId," + sql.append("select c.id as id,c.name as name,c.nid as nid,c.wx as wx,c.origin as origin,c.collect_time as collectTime,c.address as address,c.record_id as recordId," +
"cm.create_time as createTime,c.amount as amount,c.platform as platform,c.tag as tag,c.audio_url as audioUrl,c.cast_info as castInfo,c.is_encryption as isEncryption, cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," + "cm.create_time as createTime,c.amount as amount,c.platform as platform,c.tag as tag,c.audio_url as audioUrl,c.cast_info as castInfo,c.is_encryption as isEncryption, cm.remark as remark,cm.member_status as memberStatus,cm.organize_id as organizeId,cm.member_id as memberId," +
"cm.optimistic_version as optimisticVersion,cm.source_label as sourceLabel,cm.task_id as taskId,cm.clue_stage as clueStage,cm.clue_call_status as clueCallStatus," + "cm.optimistic_version as optimisticVersion,cm.source_label as sourceLabel,cm.task_id as taskId,cm.clue_stage as clueStage,cm.clue_call_status as clueCallStatus," +
"cm.newest_call_time as newestCallTime ,cm.turnover_amount as turnoverAmount ,cm.clue_type as clueType " + "cm.newest_call_time as newestCallTime ,cm.turnover_amount as turnoverAmount ,cm.clue_type as clueType ,cm.is_freeze as isFreeze " +
"from tb_clue as c LEFT JOIN tb_clue_talk as cm on c.id = cm.clue_id where 1=1 "); "from tb_clue as c LEFT JOIN tb_clue_talk as cm on c.id = cm.clue_id where 1=1 ");
List confirmReceipt = getConfirmReceipt(clueQueryCriteria, sql, pageable); List confirmReceipt = getConfirmReceipt(clueQueryCriteria, sql, pageable);
return getTradeInfo(confirmReceipt, clueQueryCriteria.getClueType(), clueQueryCriteria.getIsAdmin()); return getTradeInfo(confirmReceipt, clueQueryCriteria.getClueType(), clueQueryCriteria.getIsAdmin());
@ -132,7 +132,7 @@ public class ClueJpa {
if (id != null) { if (id != null) {
sql.append("and c.id = :id "); sql.append("and c.id = :id ");
} }
if (nid != null) { if (StrUtil.isNotBlank(nid)) {
sql.append("and c.nid = :nid "); sql.append("and c.nid = :nid ");
} }
if (StringUtils.isNotBlank(name)) { if (StringUtils.isNotBlank(name)) {
@ -202,7 +202,7 @@ public class ClueJpa {
if (id != null) { if (id != null) {
query.setParameter("id", id); query.setParameter("id", id);
} }
if (nid != null) { if (StrUtil.isNotBlank(nid)) {
query.setParameter("nid", AESUtils.encrypt(nid, secret)); query.setParameter("nid", AESUtils.encrypt(nid, secret));
} }
if (StringUtils.isNotBlank(name)) { if (StringUtils.isNotBlank(name)) {
@ -339,6 +339,7 @@ public class ClueJpa {
clueDto.setTurnoverAmount((Double) row.get("turnoverAmount")); clueDto.setTurnoverAmount((Double) row.get("turnoverAmount"));
clueDto.setCastInfo((String) row.get("castInfo")); clueDto.setCastInfo((String) row.get("castInfo"));
clueDto.setClueType((Integer) row.get("clueType")); clueDto.setClueType((Integer) row.get("clueType"));
clueDto.setIsFreeze((Boolean) row.get("isFreeze"));
clueDtoList.add(clueDto); clueDtoList.add(clueDto);
} }
return clueDtoList; return clueDtoList;
@ -520,7 +521,7 @@ public class ClueJpa {
*/ */
@Transactional(rollbackOn = Exception.class) @Transactional(rollbackOn = Exception.class)
public List<ClueTalkDTO> getReportCallInfo(String beginTime, String endTime, Long managerId) { 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 ,tcm.member_status as memberStatus,tc.create_by as managerId " + StringBuilder sql = new StringBuilder("select tcm.newest_call_time as newestCallTime,tcm.clue_call_status as clueCallStatus ,tcm.member_status as memberStatus,tc.create_by as managerId,tcm.clue_id as clueId " +
"from tb_clue_talk as tcm left join tb_clue as tc on tcm.clue_id =tc.id " + "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 "); " where tcm.newest_call_time between :beginTime and :endTime ");
if (managerId != null) { if (managerId != null) {
@ -544,6 +545,8 @@ public class ClueJpa {
clueDto.setClueCallStatus((Integer) row.get("clueCallStatus")); clueDto.setClueCallStatus((Integer) row.get("clueCallStatus"));
clueDto.setNewestCallTime((Date) row.get("newestCallTime")); clueDto.setNewestCallTime((Date) row.get("newestCallTime"));
clueDto.setMemberStatus((Integer) row.get("memberStatus")); clueDto.setMemberStatus((Integer) row.get("memberStatus"));
BigInteger clueId = (BigInteger) row.get("clueId");
clueDto.setClueId(clueId.longValue());
clueDtoList.add(clueDto); clueDtoList.add(clueDto);
} }
return clueDtoList; return clueDtoList;

@ -106,4 +106,9 @@ public interface ClueTalkRepository extends JpaRepository<ClueTalk, Long>, JpaSp
@Query(value = " select count(*) from tb_clue_talk as tcm left join tb_clue as tc on tcm.clue_id =tc.id" + @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 and tcm.create_time between ?2 and ?3", nativeQuery = true) " where tc.create_by = ?1 and tcm.create_time between ?2 and ?3", nativeQuery = true)
Integer countByCreateTime(Long userId, String startTime, String endTime); Integer countByCreateTime(Long userId, String startTime, String endTime);
@Modifying
@Query(value = " update tb_clue_talk set is_freeze = ?2 where clue_id = ?1 ", nativeQuery = true)
void updateTalkClueFreeze(Long clueId, Boolean isFreeze);
} }

@ -26,6 +26,10 @@ public class ClueTalk extends BaseClueMiddle {
@NotNull(message = "资源id不能为空") @NotNull(message = "资源id不能为空")
private Long clueId; private Long clueId;
@ApiModelProperty(value = "是否冻结")
@Column(name = "is_freeze")
private Boolean isFreeze;
@Transient @Transient
private String clueName; private String clueName;
@Transient @Transient
@ -46,7 +50,8 @@ public class ClueTalk extends BaseClueMiddle {
super(taskId, memberStatus, optimisticVersion, clueStage, clueCallStatus, clueType, clueStageTime, memberId); super(taskId, memberStatus, optimisticVersion, clueStage, clueCallStatus, clueType, clueStageTime, memberId);
this.clueId = clueId; this.clueId = clueId;
} }
public ClueTalk(){
public ClueTalk() {
} }
} }

@ -28,7 +28,7 @@ public class ReportTokerCall {
@Column(name = "create_time") @Column(name = "create_time")
@ApiModelProperty(value = "创建时间") @ApiModelProperty(value = "创建时间")
@JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT-8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT-8")
private Date createTime; private Date createTime;
@ApiModelProperty(value = "使用数") @ApiModelProperty(value = "使用数")
@ -62,6 +62,7 @@ public class ReportTokerCall {
this.setUsrNumRate(0.00); this.setUsrNumRate(0.00);
this.setTurnOnNum(0); this.setTurnOnNum(0);
this.setTurnOnRate(0.00); this.setTurnOnRate(0.00);
this.setEffectiveNum(0);
return this; return this;
} }
} }

@ -166,11 +166,12 @@ public interface ClueService {
/** /**
* 线 * 线
* @param tagList tag *
* @param tagList tag
* @param phoneList * @param phoneList
* @param taskId id * @param taskId id
* @param userId id * @param userId id
* @param num * @param num
* @return * @return
*/ */
Integer saveClue(List<String> tagList, List<String> phoneList, Long taskId, Long userId, Integer num); Integer saveClue(List<String> tagList, List<String> phoneList, Long taskId, Long userId, Integer num);
@ -186,4 +187,11 @@ public interface ClueService {
* @param map key:ID value: * @param map key:ID value:
*/ */
Boolean updateClueOrganize(Map<Long, Long> map); Boolean updateClueOrganize(Map<Long, Long> map);
/**
* 线
* @param clueId
* @param isFreeze
*/
void updateTalkClueFreeze(Long clueId, Boolean isFreeze);
} }

@ -16,4 +16,6 @@ public class ClueTalkDTO {
private Integer clueCallStatus; private Integer clueCallStatus;
private Integer memberStatus; private Integer memberStatus;
private Long clueId;
} }

@ -223,7 +223,7 @@ public class ClueServiceImpl implements ClueService {
Long count = this.findClueCount(clueQueryCriteria); Long count = this.findClueCount(clueQueryCriteria);
//手机号搜索 //手机号搜索
if (StringUtils.isNotBlank(nid)) { if (!StrUtil.isBlank(nid)) {
clueDtoList = clueDtoList.stream().filter(ct -> ct.getNid().contains(nid)).collect(Collectors.toList()); clueDtoList = clueDtoList.stream().filter(ct -> ct.getNid().contains(nid)).collect(Collectors.toList());
} }
@ -494,15 +494,16 @@ public class ClueServiceImpl implements ClueService {
ClueMiddle clueMiddle = clueMiddleRepository.findById(clueId).orElseGet(ClueMiddle::new); ClueMiddle clueMiddle = clueMiddleRepository.findById(clueId).orElseGet(ClueMiddle::new);
ClueTalk clueTalk = clueTalkRepository.findById(clueId).orElseGet(ClueTalk::new); ClueTalk clueTalk = clueTalkRepository.findById(clueId).orElseGet(ClueTalk::new);
if (clueTalk.getClueId() != null && clueTalk.getClueType() != 2) throw new BadRequestException("无法删除非个人上传资源"); if (clueTalk.getClueId() != null && clueTalk.getClueType() != 2) throw new BadRequestException("无法删除非个人上传资源");
if (clueMiddle.getClueId() != null && clueMiddle.getClueType() != 2) throw new BadRequestException("无法删除非个人上传资源"); if (clueMiddle.getClueId() != null && clueMiddle.getClueType() != 2)
throw new BadRequestException("无法删除非个人上传资源");
Set<Long> clueIds = Collections.singleton(clueId); Set<Long> clueIds = Collections.singleton(clueId);
ClueQueryCriteria clueQueryCriteria = new ClueQueryCriteria(); ClueQueryCriteria clueQueryCriteria = new ClueQueryCriteria();
clueQueryCriteria.setId(clueId); clueQueryCriteria.setId(clueId);
List<ClueDto> clueAll = clueJpa.getClueList(clueQueryCriteria, null); List<ClueDto> clueAll = clueJpa.getClueList(clueQueryCriteria, null);
this.delete(clueAll ,clueIds); this.delete(clueAll, clueIds);
if (clueTalk.getClueId() != null ) clueTalkRepository.deleteById(clueId); if (clueTalk.getClueId() != null) clueTalkRepository.deleteById(clueId);
if (clueMiddle.getClueId() != null) clueMiddleRepository.deleteById(clueId); if (clueMiddle.getClueId() != null) clueMiddleRepository.deleteById(clueId);
} }
@ -951,6 +952,12 @@ public class ClueServiceImpl implements ClueService {
return true; return true;
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void updateTalkClueFreeze(Long clueId, Boolean isFreeze) {
clueTalkRepository.updateTalkClueFreeze(clueId, isFreeze);
}
private HashMap<String, Object> getReportMap(List<ClueMiddle> clueMiddles) { private HashMap<String, Object> getReportMap(List<ClueMiddle> clueMiddles) {
int newClue = 0; int newClue = 0;
int communicat = 0; int communicat = 0;

@ -7,13 +7,13 @@ import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.StrPool; import cn.hutool.core.text.StrPool;
import cn.hutool.core.text.csv.CsvData; import cn.hutool.core.text.csv.*;
import cn.hutool.core.text.csv.CsvReader; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.text.csv.CsvUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baiye.config.properties.DeliveryProperties; import com.baiye.config.properties.DeliveryProperties;
import com.baiye.constant.AdPlatFormConstants;
import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.DefaultNumberConstants;
import com.baiye.constant.SecurityConstants; import com.baiye.constant.SecurityConstants;
import com.baiye.feign.DeliveryRecordClient; import com.baiye.feign.DeliveryRecordClient;
@ -115,53 +115,49 @@ public class MailSourceTask {
CompressUtil.unzipFiles(deliveryProperties.getFileUrl(), CompressUtil.unzipFiles(deliveryProperties.getFileUrl(),
path, deliveryProperties.getZipPassword()); path, deliveryProperties.getZipPassword());
if (ObjectUtil.isNotNull(byTaskName.getType())) { if (ObjectUtil.isNotNull(byTaskName.getType())) {
if (byTaskName.getType() == DefaultNumberConstants.ONE_NUMBER File file = new File(unzipPath);
|| byTaskName.getType() == DefaultNumberConstants.THREE_NUMBER) { File parseFile = Objects.requireNonNull
File file = new File(unzipPath); (file.listFiles())[DefaultNumberConstants.ZERO_NUMBER];
File parseFile = Objects.requireNonNull // 解析文件
(file.listFiles())[DefaultNumberConstants.ZERO_NUMBER]; CsvData data = reader.read(parseFile);
// 解析文件 // csv通配
CsvData data = reader.read(parseFile); data.getRows().forEach(clue -> {
// csv通配 phoneList.add(clue.size() == DefaultNumberConstants.THREE_NUMBER
data.getRows().forEach(clue -> { ? clue.get(DefaultNumberConstants.TWO_NUMBER) : clue.get(DefaultNumberConstants.THREE_NUMBER));
phoneList.add(clue.size() == DefaultNumberConstants.THREE_NUMBER tagList.add(clue.size() == DefaultNumberConstants.THREE_NUMBER
? clue.get(DefaultNumberConstants.TWO_NUMBER) : clue.get(DefaultNumberConstants.THREE_NUMBER)); ? clue.get(DefaultNumberConstants.ZERO_NUMBER) : clue.get(DefaultNumberConstants.ONE_NUMBER));
tagList.add(clue.size() == DefaultNumberConstants.THREE_NUMBER });
? clue.get(DefaultNumberConstants.ZERO_NUMBER) : clue.get(DefaultNumberConstants.ONE_NUMBER)); // 去除重复
}); List<String> phoneSets = Lists.newArrayList(Sets.newHashSet(phoneList));
// 去除重复 log.info("=============== the phone list as {} ==================", phoneList.size());
List<String> phoneSets = Lists.newArrayList(Sets.newHashSet(phoneList)); // 集合分割
log.info("=============== the phone list as {} ==================", phoneList.size()); List<List<String>> partitions = ListUtil.partition(phoneSets, DefaultNumberConstants.TWO_HUNDRED);
// 集合分割 for (List<String> partition : partitions) {
List<List<String>> partitions = ListUtil.partition(phoneSets, DefaultNumberConstants.TWO_HUNDRED); String join = Joiner.on(StrPool.COMMA).skipNulls().join(partition);
for (List<String> partition : partitions) { // 批量解析号码
String join = Joiner.on(StrPool.COMMA).skipNulls().join(partition); SecretResponseBean responseBean = DecryptPnoUtil.batchDecryptPno
// 批量解析号码 (Base64.encode(StringUtils.substringBeforeLast(join, StrPool.COMMA)));
SecretResponseBean responseBean = DecryptPnoUtil.batchDecryptPno if (ObjectUtil.isNotNull(responseBean) && ObjectUtil.isNotNull(responseBean.getTels())) {
(Base64.encode(StringUtils.substringBeforeLast(join, StrPool.COMMA))); String decodeStr = Base64.decodeStr(responseBean.getTels());
if (ObjectUtil.isNotNull(responseBean) && ObjectUtil.isNotNull(responseBean.getTels())) { String[] split = decodeStr.split(StrPool.COMMA);
String decodeStr = Base64.decodeStr(responseBean.getTels()); if (split.length > DefaultNumberConstants.ZERO_NUMBER) {
String[] split = decodeStr.split(StrPool.COMMA); decryptList.addAll(Lists.newArrayList(Arrays.asList(split)));
if (split.length > DefaultNumberConstants.ZERO_NUMBER) {
decryptList.addAll(Lists.newArrayList(Arrays.asList(split)));
}
}
}
// 剔除空值
decryptList = decryptList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
// 请求黑名单
if (CollUtil.isNotEmpty(decryptList)) {
log.info("=================== the decryptList size as {} =====================", decryptList.size());
if (byTaskName.getType() == DefaultNumberConstants.ONE_NUMBER) {
saveClue(taskName, byTaskName, task, taskId, tagList, decryptList, path, unzipPath);
}
if (byTaskName.getType() == DefaultNumberConstants.THREE_NUMBER) {
sendRequest(taskName, tagList, decryptList, path, unzipPath);
} }
} }
} }
if (byTaskName.getType() == DefaultNumberConstants.TWO_NUMBER) { // 剔除空值
downResource(taskName, byTaskName, decryptList, path); decryptList = decryptList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
if (CollUtil.isNotEmpty(decryptList)) {
log.info("=================== the decryptList size as {} =====================", decryptList.size());
if (byTaskName.getType() == DefaultNumberConstants.ONE_NUMBER) {
saveClue(taskName, byTaskName, task, taskId, tagList, decryptList, path, unzipPath);
}
if (byTaskName.getType() == DefaultNumberConstants.THREE_NUMBER) {
sendRequest(taskName, tagList, decryptList, path, unzipPath);
}
if (byTaskName.getType() == DefaultNumberConstants.TWO_NUMBER) {
downResource(taskName, byTaskName, decryptList, path, data.getRows(), parseFile);
}
} }
} }
} }
@ -170,8 +166,19 @@ public class MailSourceTask {
} }
} }
private void downResource(String taskName, DeliveryRecord byTaskName, List<String> decryptList, String path) {
private void downResource(String taskName, DeliveryRecord byTaskName, List<String> decryptList, String path, List<CsvRow> rows, File parseFile) {
log.info("========================= the path as {} =========================", path); log.info("========================= the path as {} =========================", path);
CsvWriter writer = CsvUtil.getWriter(parseFile, CharsetUtil.CHARSET_UTF_8);
for (int i = 0; i < decryptList.size(); i++) {
List<String> rawList = rows.get(i).getRawList();
rawList.add(EncryptUtil.aesEncrypt(decryptList.get(i), AdPlatFormConstants.PLAT_DECRYPTION));
String[] addStr = rawList.toArray(new String[rawList.size() + 1]);
writer.writeLine(addStr);
}
writer.close();
// 设置压缩文件
CompressUtil.decryptionCompression(path, parseFile.getPath(), null);
String filePath = path.substring(path.lastIndexOf(StrPool.SLASH) + DefaultNumberConstants.ONE_NUMBER); String filePath = path.substring(path.lastIndexOf(StrPool.SLASH) + DefaultNumberConstants.ONE_NUMBER);
deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, decryptList.size(), taskName); deliveryRecordService.updateStatusByTaskName(DefaultNumberConstants.ONE_NUMBER, decryptList.size(), taskName);
deliveryRecordClient.updatePath(deliveryProperties.getDmpDownPath().concat(filePath), byTaskName.getId(), SecurityConstants.FROM_IN); deliveryRecordClient.updatePath(deliveryProperties.getDmpDownPath().concat(filePath), byTaskName.getId(), SecurityConstants.FROM_IN);
@ -253,3 +260,4 @@ public class MailSourceTask {
} }
} }

@ -6,10 +6,7 @@ import cn.hutool.core.util.NumberUtil;
import com.baiye.constant.DefaultNumberConstants; import com.baiye.constant.DefaultNumberConstants;
import com.baiye.constant.SourceLabelConstants; import com.baiye.constant.SourceLabelConstants;
import com.baiye.feign.UserClient; import com.baiye.feign.UserClient;
import com.baiye.module.dao.ClueJpa; import com.baiye.module.dao.*;
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.ClueTalk;
import com.baiye.module.entity.ReportToker; import com.baiye.module.entity.ReportToker;
import com.baiye.module.entity.ReportTokerCall; import com.baiye.module.entity.ReportTokerCall;
@ -36,6 +33,8 @@ public class ReportSync {
private final ClueJpa clueJpa; private final ClueJpa clueJpa;
private final ReportTokerCallRepository repository; private final ReportTokerCallRepository repository;
private final AllCallInfoRepository allCallInfoRepository;
/** /**
* 23 * 23
*/ */
@ -122,17 +121,27 @@ public class ReportSync {
} }
ReportTokerCall talkReport = new ReportTokerCall().init(); ReportTokerCall talkReport = new ReportTokerCall().init();
List<ClueTalkDTO> clueTalks = talkByManagerId.get(key); List<ClueTalkDTO> clueTalks = talkByManagerId.get(key);
//记录使用过的线索
List<Long> usrClueIds = new ArrayList<>();
for (ClueTalkDTO clueTalk : clueTalks) { for (ClueTalkDTO clueTalk : clueTalks) {
if (clueTalk.getClueCallStatus() == DefaultNumberConstants.ONE_NUMBER) { if (clueTalk.getClueCallStatus() == DefaultNumberConstants.ONE_NUMBER || clueTalk.getClueCallStatus() == DefaultNumberConstants.TWO_NUMBER) {
talkReport.setUsrNum(talkReport.getUsrNum() + 1);
} else if (clueTalk.getClueCallStatus() == DefaultNumberConstants.TWO_NUMBER) {
talkReport.setTurnOnNum(talkReport.getTurnOnNum() + 1);
talkReport.setUsrNum(talkReport.getUsrNum() + 1); talkReport.setUsrNum(talkReport.getUsrNum() + 1);
usrClueIds.add(clueTalk.getClueId());
} }
// else if () {
// talkReport.setTurnOnNum(talkReport.getTurnOnNum() + 1);
// talkReport.setUsrNum(talkReport.getUsrNum() + 1);
// }
if (clueTalk.getMemberStatus() == DefaultNumberConstants.FOUR_NUMBER) { if (clueTalk.getMemberStatus() == DefaultNumberConstants.FOUR_NUMBER) {
talkReport.setEffectiveNum(talkReport.getEffectiveNum() + 1); talkReport.setEffectiveNum(talkReport.getEffectiveNum() + 1);
} }
} }
if (CollUtil.isNotEmpty(usrClueIds)) {
List<Long> turnOnClue = allCallInfoRepository.findTurnOnClue(2, beginOfDay, endOfDay, usrClueIds);
if (CollUtil.isNotEmpty(turnOnClue)) {
talkReport.setTurnOnNum(turnOnClue.size());
}
}
rate(talkReport, totalNum); rate(talkReport, totalNum);
talkReport.setManagerId(key); talkReport.setManagerId(key);
list.add(talkReport); list.add(talkReport);

Loading…
Cancel
Save