|
- package com.simple.controller;
-
- import java.text.NumberFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
-
- import com.simple.common.ResultData;
- import com.simple.domain.dto.WxCuerBasicInfoDto;
- import com.simple.domain.vo.TouchUsersReportVo;
- import com.simple.domain.vo.UserStructureVo;
- import com.simple.service.WxCUserService;
- import com.simple.service.WxUserVisitService;
-
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
-
- @RestController
- @RequestMapping("wxCUserData")
- @Api(description="会员首页报表数据")
- public class WxCUserDataController extends BaseController{
-
- @Autowired
- private WxCUserService wxCUserService;
- @Autowired
- private WxUserVisitService wxUserVisitService;
-
- @GetMapping("findUserCountData")
- @ApiOperation("查询用户数量接口")
- public ResultData findUserCountData() {
- WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto();
- long allCount = wxCUserService.findCount(dto);//总数
- Calendar c = Calendar.getInstance();
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE,0);
- c.set(Calendar.SECOND,0);
- Date today = c.getTime();
- // dto.setStartTime(today);
- // dto.setEndTime(null);
- // long todayCount= wxCUserService.findCount( dto);//今天新增
- // System.out.println(todayCount);
- long todayCount=0;
- long yesterdayCount =0;
- long dayOfWeekCount=0;
- List<UserStructureVo> newCountVos = new ArrayList<>();//每日新增会员数
- int j=0;
- for(int i=7;i>=0;i--) {
- c.clear();
- c.setTime(today);
- c.add(Calendar.DAY_OF_YEAR, -i);
- dto.setStartTime(c.getTime());
- c.add(Calendar.DAY_OF_YEAR, 1);
- dto.setEndTime(c.getTime());
- long count= wxCUserService.findCount(dto);
- UserStructureVo vo = new UserStructureVo();
- vo.setSortNum(j);
- j++;
- vo.setName(new SimpleDateFormat("MM-dd").format(dto.getStartTime()));
- vo.setCount(count);
- if(i==1) {
- yesterdayCount= count;
- }
- if(i==0) {
- todayCount=count;
- }
- if(i==7) {
- dayOfWeekCount=count;//上周同比
- }else {
- newCountVos.add(vo);
- }
- }
- NumberFormat nf = NumberFormat.getPercentInstance();
- nf.setMinimumFractionDigits(2);
- String dayPercentage ="";
- if(yesterdayCount>0) {
- Long count =todayCount-yesterdayCount;
- dayPercentage=nf.format(count.doubleValue()/new Double(yesterdayCount).doubleValue());
- }else {
- dayPercentage= nf.format(new Double(todayCount).doubleValue());
- }
- String weekPercentage ="";
- if(dayOfWeekCount>0) {
- Long count =todayCount-dayOfWeekCount;
- weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
- }else {
- weekPercentage= nf.format(new Double(todayCount).doubleValue());
- }
- Map<String,Object> map = new HashMap<>();
- map.put("allCount", allCount);
- map.put("todayCount", todayCount);
- map.put("newCountVos", newCountVos);
- map.put("dayPercentage",dayPercentage);//日环比
- map.put("weekPercentage",weekPercentage); //周同比
- return new ResultData(map);
- }
-
- @GetMapping("findUserVisitData")
- public ResultData findUserVisitData() {
- HashMap<String, Object> params =new HashMap<>();
- Calendar c = Calendar.getInstance();
- c.add(Calendar.DAY_OF_YEAR, -1);
- c.set(Calendar.HOUR_OF_DAY, 0);
- c.set(Calendar.MINUTE,0);
- c.set(Calendar.SECOND,0);
- Date endTime = c.getTime();
- c.add(Calendar.DAY_OF_YEAR, -30);
- Date startTime = c.getTime();
- params.put("startTime", startTime);
- params.put("endTime", endTime);
- params.put("tenantId", getTenantId());
- List<TouchUsersReportVo> list = wxUserVisitService.touchUsersReportList(params);
- Map<String,TouchUsersReportVo> dateMap = new HashMap<>();
- for(TouchUsersReportVo vo :list) {
- dateMap.put(vo.getxTime(), vo);
- }
- List<UserStructureVo> weekVos = new ArrayList<>();//每周uv
- List<UserStructureVo> monthVos =new ArrayList<>();//每月uv
- int j=1;
- long yesterdayCount =0;//昨天活跃数
- long beforeYesterdayCount=0;//前天活跃数
- long thisMonthCount=0;//月总数
- long dayOfWeekCount=0;//上周周x数
- for(int i=6;i>=0;i--) {
- c.clear();
- c.setTime(endTime);
- c.add(Calendar.DAY_OF_YEAR, -i);
- String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- UserStructureVo vo = new UserStructureVo();
- vo.setName(dayStr);
- vo.setSortNum(j);
- j++;
- if(dateMap.get(dayStr)!=null) {
- TouchUsersReportVo rv = dateMap.get(dayStr);
- Long l = new Long((long) rv.getUv());
- vo.setCount(l);
- }else {
- vo.setCount(0);
- }
- weekVos.add(vo);
- }
-
- j=1;
- for(int i=29;i>=0;i--) {
- c.clear();
- c.setTime(endTime);
- c.add(Calendar.DAY_OF_YEAR, -i);
- String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
- UserStructureVo vo = new UserStructureVo();
- vo.setName(dayStr);
- vo.setSortNum(j);
- if(dateMap.get(dayStr)!=null) {
- TouchUsersReportVo rv = dateMap.get(dayStr);
- Long l = new Long((long) rv.getUv());
- vo.setCount(l);
- }else {
- vo.setCount(0);
- }
- thisMonthCount+=vo.getCount();
- if(i==0) {
- yesterdayCount =vo.getCount();
- }
- if(i==1) {
- beforeYesterdayCount =vo.getCount();
- }
- if(i==7) {
- dayOfWeekCount=vo.getCount();
- }
-
- monthVos.add(vo);
- j++;
- }
- NumberFormat nf = NumberFormat.getPercentInstance();
- nf.setMinimumFractionDigits(2);
- String dayPercentage ="";
- if(beforeYesterdayCount>0) {
- Long count =yesterdayCount-beforeYesterdayCount;
- dayPercentage=nf.format(count.doubleValue()/new Double(beforeYesterdayCount).doubleValue());
- }else {
- dayPercentage= nf.format(new Double(yesterdayCount).doubleValue());
- }
- String weekPercentage ="";
- if(dayOfWeekCount>0) {
- Long count =yesterdayCount-dayOfWeekCount;
- weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
- }else {
- weekPercentage= nf.format(new Double(yesterdayCount).doubleValue());
- }
- Map<String,Object> mapVo =new HashMap<>();
- mapVo.put("yesterdayCount", yesterdayCount);//昨日活跃数
- mapVo.put("thisMonthCount", thisMonthCount);//近一个月活跃数
- mapVo.put("weekVos", weekVos);//上周活跃数
- mapVo.put("monthVos", monthVos);//上月活跃数
- mapVo.put("dayPercentage",dayPercentage);//日环比
- mapVo.put("weekPercentage",weekPercentage); //周同比
- return new ResultData(mapVo);
- }
-
-
- }
|