Преглед изворни кода

[会员首页报表][修改]修改日环比周同比

release_toaliyun_real
jinguo24@163.com пре 7 година
родитељ
комит
2819ad6eff
4 измењених фајлова са 221 додато и 4 уклоњено
  1. +209
    -0
      mallinkAdmin/src/main/java/com/simple/controller/WxCUserDataController.java
  2. +4
    -3
      mallinkAdmin/src/main/java/com/simple/schedule/WxAppVisitSchedule.java
  3. +2
    -1
      mallinkService/src/main/java/com/simple/service/WxUserVisitService.java
  4. +6
    -0
      mallinkService/src/main/java/com/simple/service/impl/WxUserVisitServiceImpl.java

+ 209
- 0
mallinkAdmin/src/main/java/com/simple/controller/WxCUserDataController.java Прегледај датотеку

@@ -0,0 +1,209 @@
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);
}
}

+ 4
- 3
mallinkAdmin/src/main/java/com/simple/schedule/WxAppVisitSchedule.java Прегледај датотеку

@@ -39,8 +39,8 @@ public class WxAppVisitSchedule {
private WxUserVisitService wxUserVisitService;
//@Scheduled(cron = "0 */1 * * * *?")
@Scheduled(cron = "0 0 0 * * ?")
// @Scheduled(cron = "0 */1 * * * *?")
@Scheduled(cron = "0 0 4 * * ? ")
public void start() {
try {
Calendar c =Calendar.getInstance();
@@ -69,7 +69,8 @@ public class WxAppVisitSchedule {
String body = responseEntity.getBody();
Map<String,Object> maps = (Map<String,Object>)JSON.parse(body);
JSONArray jSONArray = (JSONArray)maps.get("list");
if(jSONArray.isEmpty()) {
if(jSONArray==null || jSONArray.isEmpty()) {
logger.info("获取失败");
return;
}
JSONObject jsonObject = jSONArray.getJSONObject(0);


+ 2
- 1
mallinkService/src/main/java/com/simple/service/WxUserVisitService.java Прегледај датотеку

@@ -3,6 +3,7 @@ package com.simple.service;
import java.util.*;
import com.github.pagehelper.PageInfo;
import com.simple.domain.po.WxUserVisit;
import com.simple.domain.vo.TouchUsersReportVo;

public interface WxUserVisitService {

@@ -39,7 +40,7 @@ public interface WxUserVisitService {
void deleteById(Long id);
List<TouchUsersReportVo> touchUsersReportList(HashMap<String,Object> params);



+ 6
- 0
mallinkService/src/main/java/com/simple/service/impl/WxUserVisitServiceImpl.java Прегледај датотеку

@@ -4,6 +4,7 @@ import java.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.simple.domain.po.WxUserVisit;
import com.simple.domain.vo.TouchUsersReportVo;
import com.simple.mapper.WxUserVisitMapper;
import com.simple.service.WxUserVisitService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -43,6 +44,11 @@ public class WxUserVisitServiceImpl implements WxUserVisitService {
public void deleteById(Long id) {
wxUserVisitMapper.deleteByPrimaryKey(id);
}

@Override
public List<TouchUsersReportVo> touchUsersReportList(HashMap<String, Object> params) {
return wxUserVisitMapper.touchUsersReportList(params);
}


Loading…
Откажи
Сачувај