You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

210 lines
7.1 KiB

  1. package com.simple.controller;
  2. import java.text.NumberFormat;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import org.springframework.beans.BeanUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import com.simple.common.ResultData;
  16. import com.simple.domain.dto.WxCuerBasicInfoDto;
  17. import com.simple.domain.vo.TouchUsersReportVo;
  18. import com.simple.domain.vo.UserStructureVo;
  19. import com.simple.service.WxCUserService;
  20. import com.simple.service.WxUserVisitService;
  21. import io.swagger.annotations.Api;
  22. import io.swagger.annotations.ApiOperation;
  23. @RestController
  24. @RequestMapping("wxCUserData")
  25. @Api(description="会员首页报表数据")
  26. public class WxCUserDataController extends BaseController{
  27. @Autowired
  28. private WxCUserService wxCUserService;
  29. @Autowired
  30. private WxUserVisitService wxUserVisitService;
  31. @GetMapping("findUserCountData")
  32. @ApiOperation("查询用户数量接口")
  33. public ResultData findUserCountData() {
  34. WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto();
  35. long allCount = wxCUserService.findCount(dto);//总数
  36. Calendar c = Calendar.getInstance();
  37. c.set(Calendar.HOUR_OF_DAY, 0);
  38. c.set(Calendar.MINUTE,0);
  39. c.set(Calendar.SECOND,0);
  40. Date today = c.getTime();
  41. // dto.setStartTime(today);
  42. // dto.setEndTime(null);
  43. // long todayCount= wxCUserService.findCount( dto);//今天新增
  44. // System.out.println(todayCount);
  45. long todayCount=0;
  46. long yesterdayCount =0;
  47. long dayOfWeekCount=0;
  48. List<UserStructureVo> newCountVos = new ArrayList<>();//每日新增会员数
  49. int j=0;
  50. for(int i=7;i>=0;i--) {
  51. c.clear();
  52. c.setTime(today);
  53. c.add(Calendar.DAY_OF_YEAR, -i);
  54. dto.setStartTime(c.getTime());
  55. c.add(Calendar.DAY_OF_YEAR, 1);
  56. dto.setEndTime(c.getTime());
  57. long count= wxCUserService.findCount(dto);
  58. UserStructureVo vo = new UserStructureVo();
  59. vo.setSortNum(j);
  60. j++;
  61. vo.setName(new SimpleDateFormat("MM-dd").format(dto.getStartTime()));
  62. vo.setCount(count);
  63. if(i==1) {
  64. yesterdayCount= count;
  65. }
  66. if(i==0) {
  67. todayCount=count;
  68. }
  69. if(i==7) {
  70. dayOfWeekCount=count;//上周同比
  71. }else {
  72. newCountVos.add(vo);
  73. }
  74. }
  75. NumberFormat nf = NumberFormat.getPercentInstance();
  76. nf.setMinimumFractionDigits(2);
  77. String dayPercentage ="";
  78. if(yesterdayCount>0) {
  79. Long count =todayCount-yesterdayCount;
  80. dayPercentage=nf.format(count.doubleValue()/new Double(yesterdayCount).doubleValue());
  81. }else {
  82. dayPercentage= nf.format(new Double(todayCount).doubleValue());
  83. }
  84. String weekPercentage ="";
  85. if(dayOfWeekCount>0) {
  86. Long count =todayCount-dayOfWeekCount;
  87. weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
  88. }else {
  89. weekPercentage= nf.format(new Double(todayCount).doubleValue());
  90. }
  91. Map<String,Object> map = new HashMap<>();
  92. map.put("allCount", allCount);
  93. map.put("todayCount", todayCount);
  94. map.put("newCountVos", newCountVos);
  95. map.put("dayPercentage",dayPercentage);//日环比
  96. map.put("weekPercentage",weekPercentage); //周同比
  97. return new ResultData(map);
  98. }
  99. @GetMapping("findUserVisitData")
  100. public ResultData findUserVisitData() {
  101. HashMap<String, Object> params =new HashMap<>();
  102. Calendar c = Calendar.getInstance();
  103. c.add(Calendar.DAY_OF_YEAR, -1);
  104. c.set(Calendar.HOUR_OF_DAY, 0);
  105. c.set(Calendar.MINUTE,0);
  106. c.set(Calendar.SECOND,0);
  107. Date endTime = c.getTime();
  108. c.add(Calendar.DAY_OF_YEAR, -30);
  109. Date startTime = c.getTime();
  110. params.put("startTime", startTime);
  111. params.put("endTime", endTime);
  112. params.put("tenantId", getTenantId());
  113. List<TouchUsersReportVo> list = wxUserVisitService.touchUsersReportList(params);
  114. Map<String,TouchUsersReportVo> dateMap = new HashMap<>();
  115. for(TouchUsersReportVo vo :list) {
  116. dateMap.put(vo.getxTime(), vo);
  117. }
  118. List<UserStructureVo> weekVos = new ArrayList<>();//每周uv
  119. List<UserStructureVo> monthVos =new ArrayList<>();//每月uv
  120. int j=1;
  121. long yesterdayCount =0;//昨天活跃数
  122. long beforeYesterdayCount=0;//前天活跃数
  123. long thisMonthCount=0;//月总数
  124. long dayOfWeekCount=0;//上周周x数
  125. for(int i=6;i>=0;i--) {
  126. c.clear();
  127. c.setTime(endTime);
  128. c.add(Calendar.DAY_OF_YEAR, -i);
  129. String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
  130. UserStructureVo vo = new UserStructureVo();
  131. vo.setName(dayStr);
  132. vo.setSortNum(j);
  133. j++;
  134. if(dateMap.get(dayStr)!=null) {
  135. TouchUsersReportVo rv = dateMap.get(dayStr);
  136. Long l = new Long((long) rv.getUv());
  137. vo.setCount(l);
  138. }else {
  139. vo.setCount(0);
  140. }
  141. weekVos.add(vo);
  142. }
  143. j=1;
  144. for(int i=29;i>=0;i--) {
  145. c.clear();
  146. c.setTime(endTime);
  147. c.add(Calendar.DAY_OF_YEAR, -i);
  148. String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
  149. UserStructureVo vo = new UserStructureVo();
  150. vo.setName(dayStr);
  151. vo.setSortNum(j);
  152. if(dateMap.get(dayStr)!=null) {
  153. TouchUsersReportVo rv = dateMap.get(dayStr);
  154. Long l = new Long((long) rv.getUv());
  155. vo.setCount(l);
  156. }else {
  157. vo.setCount(0);
  158. }
  159. thisMonthCount+=vo.getCount();
  160. if(i==0) {
  161. yesterdayCount =vo.getCount();
  162. }
  163. if(i==1) {
  164. beforeYesterdayCount =vo.getCount();
  165. }
  166. if(i==7) {
  167. dayOfWeekCount=vo.getCount();
  168. }
  169. monthVos.add(vo);
  170. j++;
  171. }
  172. NumberFormat nf = NumberFormat.getPercentInstance();
  173. nf.setMinimumFractionDigits(2);
  174. String dayPercentage ="";
  175. if(beforeYesterdayCount>0) {
  176. Long count =yesterdayCount-beforeYesterdayCount;
  177. dayPercentage=nf.format(count.doubleValue()/new Double(beforeYesterdayCount).doubleValue());
  178. }else {
  179. dayPercentage= nf.format(new Double(yesterdayCount).doubleValue());
  180. }
  181. String weekPercentage ="";
  182. if(dayOfWeekCount>0) {
  183. Long count =yesterdayCount-dayOfWeekCount;
  184. weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
  185. }else {
  186. weekPercentage= nf.format(new Double(yesterdayCount).doubleValue());
  187. }
  188. Map<String,Object> mapVo =new HashMap<>();
  189. mapVo.put("yesterdayCount", yesterdayCount);//昨日活跃数
  190. mapVo.put("thisMonthCount", thisMonthCount);//近一个月活跃数
  191. mapVo.put("weekVos", weekVos);//上周活跃数
  192. mapVo.put("monthVos", monthVos);//上月活跃数
  193. mapVo.put("dayPercentage",dayPercentage);//日环比
  194. mapVo.put("weekPercentage",weekPercentage); //周同比
  195. return new ResultData(mapVo);
  196. }
  197. }