补量代码
parent
d1da18d5cf
commit
4473093930
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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,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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue