|
|
|
@@ -0,0 +1,197 @@ |
|
|
|
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.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.UserStructureVo;
|
|
|
|
import com.simple.enums.EnumAgeInfo;
|
|
|
|
import com.simple.service.WxCUserBasicInfoService;
|
|
|
|
import com.simple.service.WxCUserService;
|
|
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@Api(description="会员洞察")
|
|
|
|
@RequestMapping("userAnalysis")
|
|
|
|
public class WxUserStructureController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private WxCUserBasicInfoService wxCUserBasicInfoService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private WxCUserService wxCUserService;
|
|
|
|
|
|
|
|
@ApiOperation("查询会员性别结构")
|
|
|
|
@GetMapping("/findUserSexStructure")
|
|
|
|
public ResultData findUserSexStructure(
|
|
|
|
Date startTime,Date endTime
|
|
|
|
) {
|
|
|
|
WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto();
|
|
|
|
dto.setStartTime(startTime);
|
|
|
|
if(endTime!=null) {
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.setTime(endTime);
|
|
|
|
c.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
endTime =c.getTime();
|
|
|
|
}
|
|
|
|
//保密
|
|
|
|
dto.setSex(0);
|
|
|
|
long secrecy = getCount(dto);
|
|
|
|
dto.setSex(1);
|
|
|
|
long boy = getCount(dto);
|
|
|
|
dto.setSex(2);
|
|
|
|
long girl=getCount(dto);
|
|
|
|
Long all =secrecy+boy+girl;
|
|
|
|
List<UserStructureVo> vos = new ArrayList<>();
|
|
|
|
vos.add(getVo(boy, all, "男",1));
|
|
|
|
vos.add(getVo(girl, all, "女",2));
|
|
|
|
vos.add(getVo(secrecy, all, "保密",3));
|
|
|
|
return new ResultData(vos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("查询会员年龄结构")
|
|
|
|
@GetMapping("/findUserAgeStructure")
|
|
|
|
public ResultData findUserAgeStructure( Date startTime,Date endTime) {
|
|
|
|
WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto();
|
|
|
|
dto.setStartTime(startTime);
|
|
|
|
if(endTime!=null) {
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.setTime(endTime);
|
|
|
|
c.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
endTime =c.getTime();
|
|
|
|
}
|
|
|
|
dto.setEndTime(endTime);
|
|
|
|
long all =wxCUserBasicInfoService.findCountByAge(dto);
|
|
|
|
List<UserStructureVo> vos = new ArrayList<>();
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
for(EnumAgeInfo a:EnumAgeInfo.values()) {
|
|
|
|
c.clear();
|
|
|
|
c.setTime(new Date());
|
|
|
|
c.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
c.set(Calendar.MINUTE,0);
|
|
|
|
c.set(Calendar.SECOND,0);
|
|
|
|
long count = getCountByAge(a, c,dto);
|
|
|
|
vos.add(getVo(count, all, a.getDesc(),a.getSortNum()));
|
|
|
|
}
|
|
|
|
return new ResultData(vos);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("查询会员数量")
|
|
|
|
@GetMapping("/findUserDataCount")
|
|
|
|
public ResultData findUserCount(Date startTime,Date endTime) {
|
|
|
|
WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto();
|
|
|
|
dto.setStartTime(startTime);
|
|
|
|
if(endTime!=null) {
|
|
|
|
Calendar c = Calendar.getInstance();
|
|
|
|
c.setTime(endTime);
|
|
|
|
c.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
endTime =c.getTime();
|
|
|
|
}
|
|
|
|
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);//今天新增
|
|
|
|
List<UserStructureVo> newCountVos = new ArrayList<>();//每日新增会员数
|
|
|
|
int j=1;
|
|
|
|
for(int i=29;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);
|
|
|
|
newCountVos.add(vo);
|
|
|
|
}
|
|
|
|
List<UserStructureVo> allCountVos = new ArrayList<>();//累计会员数
|
|
|
|
c.clear();
|
|
|
|
c.setTime(today);
|
|
|
|
c.add(Calendar.DAY_OF_YEAR, -30);
|
|
|
|
dto.setEndTime(c.getTime());
|
|
|
|
dto.setStartTime(null);
|
|
|
|
long firstDay = wxCUserService.findCount(dto);//统计的第一天总数
|
|
|
|
int i =0;
|
|
|
|
long sumCount=0;
|
|
|
|
for(UserStructureVo v:newCountVos) {
|
|
|
|
UserStructureVo vo = new UserStructureVo();
|
|
|
|
sumCount+=v.getCount();
|
|
|
|
vo.setCount(firstDay+sumCount);
|
|
|
|
vo.setName(v.getName());
|
|
|
|
vo.setSortNum(i+1);
|
|
|
|
allCountVos.add(vo);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
map.put("allCount", allCount);//累计会员总数
|
|
|
|
map.put("todayCount", todayCount);//今日新增会员数
|
|
|
|
map.put("allCountVos", allCountVos);//累计会员列表( 日期和数量list)
|
|
|
|
map.put("newCountVos", newCountVos);//新增会员列表(日期和数量list)
|
|
|
|
return new ResultData(map);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private long getCountByAge(EnumAgeInfo a,Calendar c, WxCuerBasicInfoDto dto ) {
|
|
|
|
c.add(Calendar.YEAR, -a.getEnd());
|
|
|
|
Date startTime = c.getTime();
|
|
|
|
c.clear();
|
|
|
|
c.setTime(startTime);
|
|
|
|
c.add(Calendar.YEAR,a.getEnd()-a.getStart());
|
|
|
|
Date endTime = c.getTime();
|
|
|
|
dto.setBirthStartTime(startTime);
|
|
|
|
dto.setBirthEndTime(endTime);
|
|
|
|
return wxCUserBasicInfoService.findCountByAge(dto);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//通过性别获取数量
|
|
|
|
private long getCount(WxCuerBasicInfoDto dto) {
|
|
|
|
// wxCUserBasicInfoService.findCountBySex(dto) basic表与cuser表示对应的,先有cuser 才有basic
|
|
|
|
//所有这里不需要再去查basic
|
|
|
|
return wxCUserService.findCount(dto);
|
|
|
|
}
|
|
|
|
|
|
|
|
private UserStructureVo getVo(long count,long all,String name,Integer num) {
|
|
|
|
UserStructureVo vo = new UserStructureVo();
|
|
|
|
vo.setSortNum(num);
|
|
|
|
vo.setName(name);
|
|
|
|
vo.setCount(count);
|
|
|
|
NumberFormat nf = NumberFormat.getPercentInstance();
|
|
|
|
nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点
|
|
|
|
if(all>0) {
|
|
|
|
vo.setPercentage(nf.format(new Long(count).doubleValue()/new Long(all).doubleValue()));
|
|
|
|
}else {
|
|
|
|
vo.setPercentage("0.00%");
|
|
|
|
}
|
|
|
|
return vo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|