Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

300 строки
10 KiB

  1. package com.simple.controller;
  2. import java.text.DecimalFormat;
  3. import java.text.NumberFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Calendar;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  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.CUserDateAmountVo;
  18. import com.simple.domain.vo.TouchUsersReportVo;
  19. import com.simple.domain.vo.UserStructureVo;
  20. import com.simple.service.WxCUserService;
  21. import com.simple.service.WxCouponOrderService;
  22. import com.simple.service.WxUserVisitService;
  23. import io.swagger.annotations.Api;
  24. import io.swagger.annotations.ApiOperation;
  25. @RestController
  26. @RequestMapping("wxCUserData")
  27. @Api(description="会员首页报表数据")
  28. public class WxCUserDataController extends BaseController{
  29. @Autowired
  30. private WxCUserService wxCUserService;
  31. @Autowired
  32. private WxUserVisitService wxUserVisitService;
  33. @Autowired
  34. private WxCouponOrderService wxCouponOrderService;
  35. @GetMapping("findUserCountData")
  36. @ApiOperation("查询用户数量接口")
  37. public ResultData findUserCountData() {
  38. WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto();
  39. long allCount = wxCUserService.findCount(dto);//总数
  40. Calendar c = Calendar.getInstance();
  41. c.set(Calendar.HOUR_OF_DAY, 0);
  42. c.set(Calendar.MINUTE,0);
  43. c.set(Calendar.SECOND,0);
  44. Date today = c.getTime();
  45. // dto.setStartTime(today);
  46. // dto.setEndTime(null);
  47. // long todayCount= wxCUserService.findCount( dto);//今天新增
  48. // System.out.println(todayCount);
  49. long todayCount=0;
  50. long yesterdayCount =0;
  51. long dayOfWeekCount=0;
  52. List<UserStructureVo> newCountVos = new ArrayList<>();//每日新增会员数
  53. int j=0;
  54. for(int i=7;i>=0;i--) {
  55. c.clear();
  56. c.setTime(today);
  57. c.add(Calendar.DAY_OF_YEAR, -i);
  58. dto.setStartTime(c.getTime());
  59. c.add(Calendar.DAY_OF_YEAR, 1);
  60. dto.setEndTime(c.getTime());
  61. long count= wxCUserService.findCount(dto);
  62. UserStructureVo vo = new UserStructureVo();
  63. vo.setSortNum(j);
  64. j++;
  65. vo.setName(new SimpleDateFormat("MM-dd").format(dto.getStartTime()));
  66. vo.setCount(count);
  67. if(i==1) {
  68. yesterdayCount= count;
  69. }
  70. if(i==0) {
  71. todayCount=count;
  72. }
  73. if(i==7) {
  74. dayOfWeekCount=count;//上周同比
  75. }else {
  76. newCountVos.add(vo);
  77. }
  78. }
  79. NumberFormat nf = NumberFormat.getPercentInstance();
  80. nf.setMinimumFractionDigits(2);
  81. String dayPercentage ="";
  82. if(yesterdayCount>0) {
  83. Long count =todayCount-yesterdayCount;
  84. dayPercentage=nf.format(count.doubleValue()/new Double(yesterdayCount).doubleValue());
  85. }else {
  86. dayPercentage= nf.format(new Double(todayCount).doubleValue());
  87. }
  88. String weekPercentage ="";
  89. if(dayOfWeekCount>0) {
  90. Long count =todayCount-dayOfWeekCount;
  91. weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
  92. }else {
  93. weekPercentage= nf.format(new Double(todayCount).doubleValue());
  94. }
  95. Map<String,Object> map = new HashMap<>();
  96. map.put("allCount", allCount);//会员总数
  97. map.put("todayCount", todayCount);//今日新增会员数
  98. map.put("newCountVos", newCountVos);//近一个月新增数列表
  99. map.put("dayPercentage",dayPercentage);//日环比
  100. map.put("weekPercentage",weekPercentage); //周同比
  101. return new ResultData(map);
  102. }
  103. @ApiOperation("查询用户活跃量")
  104. @GetMapping("findUserVisitData")
  105. public ResultData findUserVisitData() {
  106. HashMap<String, Object> params =new HashMap<>();
  107. Calendar c = Calendar.getInstance();
  108. c.add(Calendar.DAY_OF_YEAR, -1);
  109. c.set(Calendar.HOUR_OF_DAY, 0);
  110. c.set(Calendar.MINUTE,0);
  111. c.set(Calendar.SECOND,0);
  112. Date endTime = c.getTime();
  113. c.add(Calendar.DAY_OF_YEAR, -30);
  114. Date startTime = c.getTime();
  115. params.put("startTime", startTime);
  116. params.put("endTime", endTime);
  117. params.put("tenantId", getTenantId());
  118. List<TouchUsersReportVo> list = wxUserVisitService.touchUsersReportList(params);
  119. Map<String,TouchUsersReportVo> dateMap = new HashMap<>();
  120. for(TouchUsersReportVo vo :list) {
  121. dateMap.put(vo.getxTime(), vo);
  122. }
  123. List<UserStructureVo> weekVos = new ArrayList<>();//每周uv
  124. List<UserStructureVo> monthVos =new ArrayList<>();//每月uv
  125. int j=1;
  126. long yesterdayCount =0;//昨天活跃数
  127. long beforeYesterdayCount=0;//前天活跃数
  128. long thisMonthCount=0;//月总数
  129. long dayOfWeekCount=0;//上周周x数
  130. for(int i=6;i>=0;i--) {
  131. c.clear();
  132. c.setTime(endTime);
  133. c.add(Calendar.DAY_OF_YEAR, -i);
  134. String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
  135. UserStructureVo vo = new UserStructureVo();
  136. vo.setName(new SimpleDateFormat("MM-dd").format(c.getTime()));
  137. vo.setSortNum(j);
  138. j++;
  139. if(dateMap.get(dayStr)!=null) {
  140. TouchUsersReportVo rv = dateMap.get(dayStr);
  141. Long l = new Long((long) rv.getUv());
  142. vo.setCount(l);
  143. }else {
  144. vo.setCount(0);
  145. }
  146. weekVos.add(vo);
  147. }
  148. j=1;
  149. for(int i=29;i>=0;i--) {
  150. c.clear();
  151. c.setTime(endTime);
  152. c.add(Calendar.DAY_OF_YEAR, -i);
  153. String dayStr = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
  154. UserStructureVo vo = new UserStructureVo();
  155. vo.setName(new SimpleDateFormat("MM-dd").format(c.getTime()));
  156. vo.setSortNum(j);
  157. if(dateMap.get(dayStr)!=null) {
  158. TouchUsersReportVo rv = dateMap.get(dayStr);
  159. Long l = new Long((long) rv.getUv());
  160. vo.setCount(l);
  161. }else {
  162. vo.setCount(0);
  163. }
  164. thisMonthCount+=vo.getCount();
  165. if(i==0) {
  166. yesterdayCount =vo.getCount();
  167. }
  168. if(i==1) {
  169. beforeYesterdayCount =vo.getCount();
  170. }
  171. if(i==7) {
  172. dayOfWeekCount=vo.getCount();
  173. }
  174. monthVos.add(vo);
  175. j++;
  176. }
  177. NumberFormat nf = NumberFormat.getPercentInstance();
  178. nf.setMinimumFractionDigits(2);
  179. String dayPercentage ="";
  180. if(beforeYesterdayCount>0) {
  181. Long count =yesterdayCount-beforeYesterdayCount;
  182. dayPercentage=nf.format(count.doubleValue()/new Double(beforeYesterdayCount).doubleValue());
  183. }else {
  184. dayPercentage= nf.format(new Double(yesterdayCount).doubleValue());
  185. }
  186. String weekPercentage ="";
  187. if(dayOfWeekCount>0) {
  188. Long count =yesterdayCount-dayOfWeekCount;
  189. weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
  190. }else {
  191. weekPercentage= nf.format(new Double(yesterdayCount).doubleValue());
  192. }
  193. Map<String,Object> mapVo =new HashMap<>();
  194. mapVo.put("yesterdayCount", yesterdayCount);//昨日活跃数
  195. mapVo.put("thisMonthCount", thisMonthCount);//近一个月活跃数
  196. mapVo.put("weekVos", weekVos);//上周活跃数列表
  197. mapVo.put("monthVos", monthVos);//上月活跃数列表
  198. mapVo.put("dayPercentage",dayPercentage);//日环比
  199. mapVo.put("weekPercentage",weekPercentage); //周同比
  200. return new ResultData(mapVo);
  201. }
  202. @ApiOperation("查询用户消费金额")
  203. @GetMapping("findUserAmountData")
  204. private ResultData findUserAmountData() {
  205. String tenantId = getTenantId();
  206. Calendar c =Calendar.getInstance();
  207. Date today = c.getTime();
  208. c.add(Calendar.DAY_OF_YEAR, 1);
  209. c.set(Calendar.HOUR_OF_DAY, 0);
  210. c.set(Calendar.MINUTE,0);
  211. c.set(Calendar.SECOND,0);
  212. Date endTime = c.getTime();//明天0点
  213. c.add(Calendar.DAY_OF_YEAR, -30);//三十天前
  214. Date startTime = c.getTime();
  215. int thisMonthCount =wxCouponOrderService.queryPriceTotal(tenantId, startTime, endTime);//月消费金额
  216. c.clear();
  217. c.setTime(endTime);
  218. Date eTime=c.getTime();
  219. c.add(Calendar.DAY_OF_YEAR, -8);
  220. Date sTime =c.getTime();
  221. List<CUserDateAmountVo> datas = wxCouponOrderService.queryPriceTotalGroup(tenantId, sTime, eTime);
  222. Map<String,Integer> dataMap = new HashMap<>();
  223. for(CUserDateAmountVo v:datas) {
  224. dataMap.put(v.getxTime(), v.getPrice());
  225. }
  226. Integer todayCount=0;//今日金额数
  227. Integer yesterdayCount =0;//昨日金额数
  228. Integer dayOfWeekCount=0;//上周x
  229. int j=0;
  230. List<UserStructureVo> weekCountVos = new ArrayList<>();//周消费金额
  231. for(int i=7;i>=0;i--) {
  232. c.clear();
  233. c.setTime(today);
  234. c.add(Calendar.DAY_OF_YEAR, -i);
  235. String dateStr = new SimpleDateFormat("MM-dd").format(c.getTime());
  236. UserStructureVo vo = new UserStructureVo();
  237. vo.setName(new SimpleDateFormat("MM-dd").format(c.getTime()));
  238. vo.setSortNum(j);
  239. if(dataMap.get(dateStr)!=null) {
  240. int price= dataMap.get(dateStr);
  241. vo.setPrice(price);
  242. }else {
  243. vo.setPrice(0);
  244. }
  245. if(i==0) {
  246. todayCount =vo.getPrice();
  247. }
  248. if(i==1) {
  249. yesterdayCount =vo.getPrice();
  250. }
  251. if(i==7) {
  252. dayOfWeekCount=vo.getPrice();
  253. }else {
  254. weekCountVos.add(vo);
  255. }
  256. j++;
  257. }
  258. NumberFormat nf = NumberFormat.getPercentInstance();
  259. nf.setMinimumFractionDigits(2);
  260. String dayPercentage ="";
  261. if(yesterdayCount>0) {
  262. Integer count =todayCount-yesterdayCount;
  263. dayPercentage=nf.format(count.doubleValue()/new Double(yesterdayCount).doubleValue());
  264. }else {
  265. dayPercentage= nf.format(new Double(todayCount).doubleValue());
  266. }
  267. String weekPercentage ="";
  268. if(dayOfWeekCount>0) {
  269. Integer count =todayCount-dayOfWeekCount;
  270. weekPercentage=nf.format(count.doubleValue()/new Double(dayOfWeekCount).doubleValue());
  271. }else {
  272. weekPercentage= nf.format(new Double(todayCount).doubleValue());
  273. }
  274. Map<String,Object> map =new HashMap<>();
  275. DecimalFormat df=new DecimalFormat("0.00");
  276. map.put("todayCount", df.format((float)todayCount/100));//今日消费金额
  277. String thisMonthCountStr = df.format((float)thisMonthCount/100);
  278. map.put("thisMonthCount", thisMonthCountStr);//近一个月消费金额数
  279. map.put("dayPercentage",dayPercentage);//日环比
  280. map.put("weekPercentage",weekPercentage); //周同比
  281. map.put("weekCountVos", weekCountVos);//一周金额列表
  282. return new ResultData(map);
  283. }
  284. }