diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportCrmController.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportCrmController.java index f502a6a1..59fa64fa 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportCrmController.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/ReportCrmController.java @@ -8,10 +8,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; @@ -38,11 +35,13 @@ public class ReportCrmController { public CommonResponse reportCrmPie(@RequestBody ReportTokerDTO reportTokerDTO) { return CommonResponse.createBySuccess(reportCrmService.reportCrmPie(reportTokerDTO)); } + @PostMapping("/crm/download") @ApiOperation("crm统计导出") public void downloadReportCrm(HttpServletResponse response, @RequestBody ReportTokerDTO reportTokerDTO) { reportCrmService.downloadReportCrm(response, reportTokerDTO); } + @PostMapping("/crm/stage") @ApiOperation("人员跟进情况") public CommonResponse reportClueStage(@RequestBody ReportStageAndTurnoverDto reportStageAndTurnoverDto) { @@ -54,4 +53,10 @@ public class ReportCrmController { public CommonResponse reportCrmTurnover(@RequestBody ReportTokerDTO reportTokerDTO) { return CommonResponse.createBySuccess(reportCrmService.reportCrmTurnover(reportTokerDTO)); } + + @ApiOperation("下载金额记录") + @PostMapping("/turnover/download") + public void downLoadCrmTurnover(HttpServletResponse response, @RequestBody ReportTokerDTO reportTokerDTO) { + reportCrmService.downLoadCrmTurnover(response, reportTokerDTO); + } } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/TurnoverRecordController.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/TurnoverRecordController.java index 5559b86e..2995f22d 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/TurnoverRecordController.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/controller/TurnoverRecordController.java @@ -35,10 +35,10 @@ public class TurnoverRecordController { return CommonResponse.createBySuccess(); } - @ApiOperation("修改记录") - @PostMapping("/update") - public CommonResponse update(@RequestBody TurnoverRecord turnoverRecord) { - turnoverRecordService.update(turnoverRecord); + @ApiOperation("确认收款") + @GetMapping("/update") + public CommonResponse update(@RequestParam(value = "id") Long id, @RequestParam(value = "actualAmount") Double actualAmount) { + turnoverRecordService.update(id, actualAmount); return CommonResponse.createBySuccess(); } @@ -47,4 +47,5 @@ public class TurnoverRecordController { public CommonResponse query(@RequestParam(value = "clueId") Long clueId) { return CommonResponse.createBySuccess(turnoverRecordService.query(clueId)); } + } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnoverRecordRepository.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnoverRecordRepository.java index eae136ae..a7996f27 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnoverRecordRepository.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/dao/TurnoverRecordRepository.java @@ -20,9 +20,34 @@ public interface TurnoverRecordRepository extends JpaRepository findByClueId(Long clueId); - @Query(value = "select * from tb_clue_turnover_record d where d.actual_time >= ?1 and d.actual_time< ?2 and d.user_id = ?3", nativeQuery = true) + /** + * 按实际成交期筛选 + * + * @param beginTime + * @param endTime + * @param userId + * @return + */ + @Query(value = "select * from tb_clue_turnover_record d where d.actual_time between ?1 and ?2 and d.user_id = ?3", nativeQuery = true) List findByUserIdAndTime(String beginTime, String endTime, Long userId); - @Query(value = "select * from tb_clue_turnover_record d where d.actual_time >= ?1 and d.actual_time< ?2 and d.member_id = ?3", nativeQuery = true) + @Query(value = "select * from tb_clue_turnover_record d where d.actual_time between ?1 and ?2 and d.member_id = ?3", nativeQuery = true) List findByMemberIdAndTime(String beginTime, String endTime, Long memberId); + + /** + * 按预设日期筛选 + * + * @param beginTime + * @param endTime + * @param userId + * @return + */ + @Query(value = "select * from tb_clue_turnover_record d where d.turnover_time between DATE_FORMAT( ?1, '%Y-%m-%d') and DATE_FORMAT( ?2, '%Y-%m-%d') and d.user_id = ?3", nativeQuery = true) + List findByUserIdAndTurnoverTime(String beginTime, String endTime, Long userId); + + @Query(value = "select * from tb_clue_turnover_record d where d.turnover_time= ?1 and d.turnover_status = ?2", nativeQuery = true) + List findByAndTurnoverTimeAndStatus(String beninTime, Integer status); + + @Query(value = "select * from tb_clue_turnover_record d where d.turnover_time< ?1 and d.turnover_status = ?2", nativeQuery = true) + List findTimeOutByAndTurnoverTimeAndStatus(String beninTime, Integer status); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/dto/UploadCrmTurnoverDTO.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/dto/UploadCrmTurnoverDTO.java new file mode 100644 index 00000000..c5b759d7 --- /dev/null +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/entity/dto/UploadCrmTurnoverDTO.java @@ -0,0 +1,19 @@ +package com.baiye.module.entity.dto; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +@Data +public class UploadCrmTurnoverDTO { + + @ExcelProperty(value = "人员名称", index = 0) + private String memberName; + @ExcelProperty(value = "开始时间", index = 1) + private String beginTime; + @ExcelProperty(value = "结束时间", index = 2) + private String endTime; + @ExcelProperty(value = "预成交金额", index = 3) + private Double turnoverAmount; + @ExcelProperty(value = "实际成交金额", index = 4) + private Double actualAmount; +} diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportCrmService.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportCrmService.java index b316a4f3..ecaf772d 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportCrmService.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/ReportCrmService.java @@ -24,4 +24,6 @@ public interface ReportCrmService { List> reportCrmTurnover(ReportTokerDTO reportTokerDTO); void downloadReportCrm(HttpServletResponse response, ReportTokerDTO reportTokerDTO); + + void downLoadCrmTurnover(HttpServletResponse response, ReportTokerDTO reportTokerDTO); } diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/TurnoverRecordService.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/TurnoverRecordService.java index 1de17179..e92ea5b6 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/TurnoverRecordService.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/TurnoverRecordService.java @@ -23,11 +23,11 @@ public interface TurnoverRecordService { void delete(Long id); /** - * 修改 - * - * @param turnoverRecord 修改对象 + * 修改状态 + * @param id + * @param actualAmount */ - void update(TurnoverRecord turnoverRecord); + void update(Long id, Double actualAmount); /** * 查询所有的收款记录 diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportCrmServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportCrmServiceImpl.java index e6eeddb8..ad162b92 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportCrmServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportCrmServiceImpl.java @@ -27,9 +27,11 @@ import com.baiye.module.entity.Task; import com.baiye.module.entity.TurnoverRecord; import com.baiye.module.entity.dto.ReportTokerDTO; import com.baiye.module.entity.dto.UploadCrmDTO; +import com.baiye.module.entity.dto.UploadCrmTurnoverDTO; import com.baiye.module.entity.dto.UploadTokerDTO; import com.baiye.module.service.ReportCrmService; import com.baiye.util.ExportExcelUtil; +import com.baiye.util.SecurityUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.Cacheable; @@ -205,7 +207,7 @@ public class ReportCrmServiceImpl implements ReportCrmService { dealTime(reportTokerDTO, DefaultNumberConstants.ONE_NUMBER); //如果任务id为空 ,默认查询5个任务 if (CollUtil.isEmpty(reportTokerDTO.getTaskIds())) { - List taskIds = getTaskIds(reportTokerDTO.getMemberId(), DefaultNumberConstants.THREE_NUMBER); + List taskIds = getTaskIds(SecurityUtils.getCurrentUserId(), DefaultNumberConstants.THREE_NUMBER); reportTokerDTO.setTaskIds(taskIds); } List clueMiddles = clueMiddleRepository.reportClueByTaskIdAndStage(reportTokerDTO.getTaskIds(), reportTokerDTO.getBeginTime(), reportTokerDTO.getEndTime(), null); @@ -238,6 +240,37 @@ public class ReportCrmServiceImpl implements ReportCrmService { ExportExcelUtil.downloadEasyExcel(response, UploadCrmDTO.class, list, "crm-task"); } + @Override + public void downLoadCrmTurnover(HttpServletResponse response, ReportTokerDTO reportTokerDTO) { + dealTime(reportTokerDTO, DefaultNumberConstants.ONE_NUMBER); + List byUserIdAndTime = turnoverRecordRepository.findByUserIdAndTime(reportTokerDTO.getBeginTime(), reportTokerDTO.getEndTime(), SecurityUtils.getCurrentUserId()); + if (CollUtil.isEmpty(byUserIdAndTime)) { + throw new BadRequestException("无数据导出"); + } + //按人员分组 + Map> collect = byUserIdAndTime.stream().collect(Collectors.groupingBy(TurnoverRecord::getMemberId, Collectors.toList())); + List uploadCrmTurnoverDTOS = new ArrayList<>(); + for (Long key : collect.keySet()) { + List turnoverRecords = collect.get(key); + //人员名称 + String memberName = turnoverRecords.get(0).getMemberName(); + Double turnoverAmount = 0.00; + Double actualAmount = 0.00; + for (TurnoverRecord turnoverRecord : turnoverRecords) { + NumberUtil.add(turnoverAmount, turnoverRecord.getTurnoverAmount()); + NumberUtil.add(actualAmount, turnoverRecord.getActualAmount()); + } + UploadCrmTurnoverDTO uploadCrmTurnoverDTO = new UploadCrmTurnoverDTO(); + uploadCrmTurnoverDTO.setMemberName(memberName); + uploadCrmTurnoverDTO.setBeginTime(reportTokerDTO.getBeginTime()); + uploadCrmTurnoverDTO.setEndTime(reportTokerDTO.getEndTime()); + uploadCrmTurnoverDTO.setTurnoverAmount(turnoverAmount); + uploadCrmTurnoverDTO.setActualAmount(actualAmount); + uploadCrmTurnoverDTOS.add(uploadCrmTurnoverDTO); + } + ExportExcelUtil.downloadEasyExcel(response, UploadCrmTurnoverDTO.class, uploadCrmTurnoverDTOS, "crm-turnover"); + } + private List> getOrganizeInfo(String startTime, String endTime, List organizeIds) { //通过组id查询组员 Map> memberIdByOrganizeIds = organizeClient.findMemberIdByOrganizeIds(organizeIds); diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java index e18912d6..06a335c0 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/ReportTokerServiceImpl.java @@ -33,6 +33,7 @@ import com.baiye.module.entity.dto.UploadTokerDTO; import com.baiye.module.service.ReportTokerService; import com.baiye.task.ReportSync; import com.baiye.util.ExportExcelUtil; +import com.baiye.util.SecurityUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.Cacheable; @@ -169,7 +170,7 @@ public class ReportTokerServiceImpl implements ReportTokerService { public void downloadReportToker(HttpServletResponse response, ReportTokerDTO reportTokerDTO) { dealTime(reportTokerDTO, DefaultNumberConstants.ONE_NUMBER); if (CollUtil.isEmpty(reportTokerDTO.getTaskIds())) { - List taskIds = getTaskIds(reportTokerDTO.getMemberId(), DefaultNumberConstants.FIVE_NUMBER); + List taskIds = getTaskIds(SecurityUtils.getCurrentUserId(), DefaultNumberConstants.FIVE_NUMBER); reportTokerDTO.setTaskIds(taskIds); } List tokers = reportTokerRepository.queryAllByTimeAndTaskIds(reportTokerDTO.getBeginTime(), reportTokerDTO.getEndTime(), reportTokerDTO.getTaskIds()); diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/TurnoverRecordServiceImpl.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/TurnoverRecordServiceImpl.java index edef63e5..f82c83ed 100644 --- a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/TurnoverRecordServiceImpl.java +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/module/service/impl/TurnoverRecordServiceImpl.java @@ -46,26 +46,21 @@ public class TurnoverRecordServiceImpl implements TurnoverRecordService { @Override @Transactional(rollbackFor = Exception.class) - public void update(TurnoverRecord turnoverRecord) { - TurnoverRecord turnoverRecord1 = turnoverRecordRepository.findById(turnoverRecord.getId()).orElseGet(TurnoverRecord::new); - if (turnoverRecord.getActualAmount() != null) { - //如果小于预设金额,只收款部分,状态变为收款中 - if (turnoverRecord.getActualAmount() < turnoverRecord1.getTurnoverAmount()) { - turnoverRecord1.setTurnoverStatus(DefaultNumberConstants.ONE_NUMBER); - } else { - turnoverRecord1.setTurnoverStatus(DefaultNumberConstants.THREE_NUMBER); - } - turnoverRecord1.setActualAmount(turnoverRecord.getActualAmount()); - turnoverRecord1.setActualTime(new Date()); - turnoverRecordRepository.save(turnoverRecord1); - //同步到线索金额 - Long clueId = turnoverRecord1.getClueId(); - ClueMiddle clueMiddle = clueMiddleRepository.findById(clueId).orElseGet(ClueMiddle::new); - Double turnoverAmount = clueMiddle.getTurnoverAmount(); - double add = NumberUtil.add(turnoverAmount, turnoverRecord.getActualAmount()); - clueMiddle.setTurnoverAmount(add); - clueMiddleRepository.save(clueMiddle); - } + public void update(Long id, Double actualAmount) { + TurnoverRecord turnoverRecord1 = turnoverRecordRepository.findById(id).orElseGet(TurnoverRecord::new); + turnoverRecord1.setTurnoverStatus(DefaultNumberConstants.THREE_NUMBER); + turnoverRecord1.setActualAmount(actualAmount); + turnoverRecord1.setActualTime(new Date()); + turnoverRecordRepository.save(turnoverRecord1); + + //同步到线索金额 + Long clueId = turnoverRecord1.getClueId(); + ClueMiddle clueMiddle = clueMiddleRepository.findById(clueId).orElseGet(ClueMiddle::new); + Double turnoverAmount = clueMiddle.getTurnoverAmount(); + double add = NumberUtil.add(turnoverAmount, turnoverRecord1.getActualAmount()); + clueMiddle.setTurnoverAmount(add); + clueMiddleRepository.save(clueMiddle); + } @Override diff --git a/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java new file mode 100644 index 00000000..d7c7be37 --- /dev/null +++ b/ad-platform-services/ad-platform-source/src/main/java/com/baiye/task/CrmTurnoverSync.java @@ -0,0 +1,41 @@ +package com.baiye.task; + +import cn.hutool.core.date.DateUtil; +import com.baiye.module.dao.TurnoverRecordRepository; +import com.baiye.module.entity.TurnoverRecord; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.util.List; + + +/** + * @author 定时处理成交金额状态 + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class CrmTurnoverSync { + + private final TurnoverRecordRepository turnoverRecordRepository; + + /** + * 每天凌晨 0点半,查看金额成交情况 + */ +// @Scheduled(cron = "0 0/5 * * * ? ") + @Scheduled(cron = "0 30 0 * * ? ") + public void dealTurnover() { + log.info("-------------------检测成交金额记录-------------"); + String today = DateUtil.today(); + List byAndTurnoverTimeAndStatus = turnoverRecordRepository.findByAndTurnoverTimeAndStatus(today, 0); + List timeOutByAndTurnoverTimeAndStatus = turnoverRecordRepository.findTimeOutByAndTurnoverTimeAndStatus(today, 1); + + byAndTurnoverTimeAndStatus.forEach(item -> item.setTurnoverStatus(1)); + timeOutByAndTurnoverTimeAndStatus.forEach(item -> item.setTurnoverStatus(2)); + + byAndTurnoverTimeAndStatus.addAll(timeOutByAndTurnoverTimeAndStatus); + turnoverRecordRepository.saveAll(byAndTurnoverTimeAndStatus); + } +} diff --git a/ad-platform-services/ad-platform-source/src/main/resources/application.yml b/ad-platform-services/ad-platform-source/src/main/resources/application.yml index 64fa105f..991d54a1 100644 --- a/ad-platform-services/ad-platform-source/src/main/resources/application.yml +++ b/ad-platform-services/ad-platform-source/src/main/resources/application.yml @@ -49,10 +49,6 @@ security: - /logininfor - /oauth/check_token - /open/v1/form/add - - /source/report/toker/pie - - /source/report/toker/download - - /source/report/crm/download - - /source/turnoverRecord/save #hutool雪花算法 snowflake: