123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- package com.fs.company.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.fs.common.core.controller.BaseController;
- import com.fs.common.core.domain.AjaxResult;
- import com.fs.common.core.domain.R;
- import com.fs.common.utils.ServletUtils;
- import com.fs.common.utils.StringUtils;
- import com.fs.common.utils.TimeUtils;
- import com.fs.common.utils.poi.ExcelUtil;
- import com.fs.company.domain.CompanyUser;
- import com.fs.company.param.CompanyStatisticsParam;
- import com.fs.company.service.ICompanySmsLogsService;
- import com.fs.company.service.ICompanyUserService;
- import com.fs.company.service.ICompanyVoiceLogsService;
- import com.fs.company.vo.CompanyPackageOrderStatisticsVO;
- import com.fs.company.vo.CompanySmsLogsStatisticsVO;
- import com.fs.company.vo.CompanyVoiceLogsStatisticsVO;
- import com.fs.core.security.LoginUser;
- import com.fs.core.web.service.TokenService;
- import com.fs.crm.service.ICrmCustomerUserService;
- import com.fs.crm.service.ICrmCustomerVisitService;
- import com.fs.crm.vo.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * 统计
- *
- * @author fs
- * @date 2021-03-22
- */
- @RestController
- @RequestMapping("/company/statistics")
- public class CompanyStatisticsController extends BaseController
- {
- @Autowired
- private ICompanyUserService userService;
- @Autowired
- private ICompanyVoiceLogsService voiceLogsService;
- @Autowired
- private ICompanySmsLogsService smsLogsService;
- @Autowired
- private TokenService tokenService;
- @PreAuthorize("@ss.hasPermi('company:statistics:voiceLogs')")
- @GetMapping("/voiceLogs")
- public R voiceLogs(CompanyStatisticsParam param)
- {
- if(StringUtils.isNotEmpty(param.getUserIds())){
- String[] userIds=param.getUserIds().split(",");
- Long[] ids=new Long[userIds.length];
- for(int i=0;i<ids.length; i++){
- ids[i]=Long.parseLong(userIds[i]);
- }
- param.setUsers(ids);
- }
- else{
- //获取部门下的所有用户
- CompanyUser usermap=new CompanyUser();
- usermap.setDeptId(param.getDeptId());
- List<CompanyUser> users = userService.getUserListByDeptId(usermap);
- List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
- param.setUsers(userIds.toArray(new Long[userIds.size()]));
- }
- if(param.getUsers()!=null&¶m.getUsers().length>0){
- List<CompanyVoiceLogsStatisticsVO> list= voiceLogsService.selectVoiceLogsStatisticsList(param);
- if(list!=null){
- for(CompanyVoiceLogsStatisticsVO vo:list){
- double f1 = new BigDecimal((float)vo.getCallSuccessCount()/vo.getCallCount()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()*100;
- vo.setCallRate(f1);
- }
- }
- TimeUtils.TimeEntity timeEntity=TimeUtils.parseTime(param.getType().toString(),param.getStartTime(),param.getEndTime());
- timeEntity.setUserIds(param.getUsers());
- Integer cycleNum = timeEntity.getCycleNum();
- Integer beginTime = timeEntity.getBeginTime();
- List<Integer> timeList = new ArrayList<>();
- for (int i = 1; i <= cycleNum; i++) {
- timeList.add(beginTime);
- beginTime = TimeUtils.formatTime(beginTime);
- }
- List<JSONObject> jsonObjectList = voiceLogsService.selectVoiceLogsTotalCount(timeEntity.toMap());
- List<String> dates = jsonObjectList.stream().map(jsonObject -> jsonObject.getString("type")).collect(Collectors.toList());
- List<Integer> callCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("callCount")).collect(Collectors.toList());
- List<Integer> callSuccessCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("callSuccessCount")).collect(Collectors.toList());
- List<Integer> times = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("times")).collect(Collectors.toList());
- List<Integer> billingTime = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("billingTime")).collect(Collectors.toList());
- return R.ok().put("list",list).put("dates",dates).put("callCount",callCount).put("callSuccessCount",callSuccessCount).put("times",times).put("billingTime",billingTime);
- }
- else {
- return R.ok("未查找到数据");
- }
- }
- @PreAuthorize("@ss.hasPermi('company:statistics:exportVoiceLogs')")
- @GetMapping("/exportVoiceLogs")
- public AjaxResult exportVoiceLogs(CompanyStatisticsParam param)
- {
- if(StringUtils.isNotEmpty(param.getUserIds())){
- String[] userIds=param.getUserIds().split(",");
- Long[] ids=new Long[userIds.length];
- for(int i=0;i<ids.length; i++){
- ids[i]=Long.parseLong(userIds[i]);
- }
- param.setUsers(ids);
- }
- else{
- //获取所有员工
- CompanyUser usermap=new CompanyUser();
- usermap.setDeptId(param.getDeptId());
- List<CompanyUser> users = userService.getUserListByDeptId(usermap);
- List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
- param.setUsers(userIds.toArray(new Long[userIds.size()]));
- }
- List<CompanyVoiceLogsStatisticsVO> list= voiceLogsService.selectVoiceLogsStatisticsList(param);
- if(list!=null){
- for(CompanyVoiceLogsStatisticsVO vo:list){
- double f1 = new BigDecimal((float)vo.getCallSuccessCount()/vo.getCallCount()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()*100;
- vo.setCallRate(f1);
- }
- }
- ExcelUtil<CompanyVoiceLogsStatisticsVO> util = new ExcelUtil<CompanyVoiceLogsStatisticsVO>(CompanyVoiceLogsStatisticsVO.class);
- return util.exportExcel(list, "voiceLogs");
- }
- @PreAuthorize("@ss.hasPermi('company:statistics:myVoiceLogs')")
- @GetMapping("/myVoiceLogs")
- public R myVoiceLogs(CompanyStatisticsParam param)
- {
- LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
- param.setUsers(new Long[]{loginUser.getUser().getUserId()});
- if(param.getUsers()!=null&¶m.getUsers().length>0){
- List<CompanyVoiceLogsStatisticsVO> list= voiceLogsService.selectVoiceLogsStatisticsList(param);
- if(list!=null){
- for(CompanyVoiceLogsStatisticsVO vo:list){
- double f1 = new BigDecimal((float)vo.getCallSuccessCount()/vo.getCallCount()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()*100;
- vo.setCallRate(f1);
- }
- }
- TimeUtils.TimeEntity timeEntity=TimeUtils.parseTime(param.getType().toString(),param.getStartTime(),param.getEndTime());
- timeEntity.setUserIds(param.getUsers());
- Integer cycleNum = timeEntity.getCycleNum();
- Integer beginTime = timeEntity.getBeginTime();
- List<Integer> timeList = new ArrayList<>();
- for (int i = 1; i <= cycleNum; i++) {
- timeList.add(beginTime);
- beginTime = TimeUtils.formatTime(beginTime);
- }
- List<JSONObject> jsonObjectList = voiceLogsService.selectVoiceLogsTotalCount(timeEntity.toMap());
- List<String> dates = jsonObjectList.stream().map(jsonObject -> jsonObject.getString("type")).collect(Collectors.toList());
- List<Integer> callCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("callCount")).collect(Collectors.toList());
- List<Integer> callSuccessCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("callSuccessCount")).collect(Collectors.toList());
- List<Integer> times = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("times")).collect(Collectors.toList());
- List<Integer> billingTime = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("billingTime")).collect(Collectors.toList());
- return R.ok().put("list",list).put("dates",dates).put("callCount",callCount).put("callSuccessCount",callSuccessCount).put("times",times).put("billingTime",billingTime);
- }
- else {
- return R.ok("未查找到数据");
- }
- }
- @PreAuthorize("@ss.hasPermi('company:statistics:exportMyVoiceLogs')")
- @GetMapping("/exportMyVoiceLogs")
- public AjaxResult exportMyVoiceLogs(CompanyStatisticsParam param)
- {
- LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
- param.setUsers(new Long[]{loginUser.getUser().getUserId()});
- List<CompanyVoiceLogsStatisticsVO> list= voiceLogsService.selectVoiceLogsStatisticsList(param);
- if(list!=null){
- for(CompanyVoiceLogsStatisticsVO vo:list){
- double f1 = new BigDecimal((float)vo.getCallSuccessCount()/vo.getCallCount()).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()*100;
- vo.setCallRate(f1);
- }
- }
- ExcelUtil<CompanyVoiceLogsStatisticsVO> util = new ExcelUtil<CompanyVoiceLogsStatisticsVO>(CompanyVoiceLogsStatisticsVO.class);
- return util.exportExcel(list, "voiceLogs");
- }
- @PreAuthorize("@ss.hasPermi('company:statistics:smsLogs')")
- @GetMapping("/smsLogs")
- public R smsLogs(CompanyStatisticsParam param)
- {
- if(StringUtils.isNotEmpty(param.getUserIds())){
- String[] userIds=param.getUserIds().split(",");
- Long[] ids=new Long[userIds.length];
- for(int i=0;i<ids.length; i++){
- ids[i]=Long.parseLong(userIds[i]);
- }
- param.setUsers(ids);
- }
- else{
- //获取部门下的所有用户
- CompanyUser usermap=new CompanyUser();
- usermap.setDeptId(param.getDeptId());
- List<CompanyUser> users = userService.getUserListByDeptId(usermap);
- List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
- param.setUsers(userIds.toArray(new Long[userIds.size()]));
- }
- if(param.getUsers()!=null&¶m.getUsers().length>0){
- List<CompanySmsLogsStatisticsVO> list= smsLogsService.selectSmsLogsStatisticsList(param);
- TimeUtils.TimeEntity timeEntity=TimeUtils.parseTime(param.getType().toString(),param.getStartTime(),param.getEndTime());
- timeEntity.setUserIds(param.getUsers());
- Integer cycleNum = timeEntity.getCycleNum();
- Integer beginTime = timeEntity.getBeginTime();
- List<Integer> timeList = new ArrayList<>();
- for (int i = 1; i <= cycleNum; i++) {
- timeList.add(beginTime);
- beginTime = TimeUtils.formatTime(beginTime);
- }
- List<JSONObject> jsonObjectList = smsLogsService.selectSmsLogsCounts(timeEntity.toMap());
- List<String> dates = jsonObjectList.stream().map(jsonObject -> jsonObject.getString("type")).collect(Collectors.toList());
- List<Integer> smsCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("smsCount")).collect(Collectors.toList());
- List<Integer> successCount = jsonObjectList.stream().map(jsonObject -> jsonObject.getInteger("successCount")).collect(Collectors.toList());
- return R.ok().put("list",list).put("dates",dates).put("smsCount",smsCount).put("successCount",successCount);
- }
- else {
- return R.ok("未查找到数据");
- }
- }
- @PreAuthorize("@ss.hasPermi('company:statistics:exportSmsLogs')")
- @GetMapping("/exportSmsLogs")
- public AjaxResult exportSmsLogs(CompanyStatisticsParam param)
- {
- if(StringUtils.isNotEmpty(param.getUserIds())){
- String[] userIds=param.getUserIds().split(",");
- Long[] ids=new Long[userIds.length];
- for(int i=0;i<ids.length; i++){
- ids[i]=Long.parseLong(userIds[i]);
- }
- param.setUsers(ids);
- }
- else{
- //获取所有员工
- CompanyUser usermap=new CompanyUser();
- usermap.setDeptId(param.getDeptId());
- List<CompanyUser> users = userService.getUserListByDeptId(usermap);
- List<Long> userIds = users.stream().map(element -> element.getUserId()).collect(Collectors.toList());
- param.setUsers(userIds.toArray(new Long[userIds.size()]));
- }
- List<CompanySmsLogsStatisticsVO> list= smsLogsService.selectSmsLogsStatisticsList(param);
- ExcelUtil<CompanySmsLogsStatisticsVO> util = new ExcelUtil<CompanySmsLogsStatisticsVO>(CompanySmsLogsStatisticsVO.class);
- return util.exportExcel(list, "voiceLogs");
- }
- }
|