| | |
| | | package com.yeshi.fanli.service.impl.count;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | |
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.user.count.DailyCountUserDao;
|
| | | import com.yeshi.fanli.dto.order.CountOrderDTO;
|
| | | import com.yeshi.fanli.entity.admin.count.DailyCountUser;
|
| | | import com.yeshi.fanli.entity.admin.count.DailyCountUser.DailyCountUserEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.Extract;
|
| | |
| | | * @param typeEnum
|
| | | * @throws Exception
|
| | | */
|
| | | private void initData(DailyCountUserEnum typeEnum) throws Exception {
|
| | | @Override
|
| | | public void initData(DailyCountUserEnum typeEnum) throws Exception {
|
| | | Date lastDate = null;
|
| | | DailyCountUser lastRecord = dailyCountUserDao.getMaxDate(typeEnum);
|
| | | if (lastRecord != null) {
|
| | |
| | | } else {
|
| | | lastDate = TimeUtil.parse("2017-05-06");
|
| | | }
|
| | |
|
| | | long min = DateUtil.dateDiffMin(lastDate, new Date());
|
| | | if (min <= 10) { // 10分钟以内不统计
|
| | | return;
|
| | | }
|
| | | |
| | | Date today = new Date();
|
| | | int betweenDays = DateUtil.daysBetween2(lastDate, today);
|
| | | for (int i = 0; i <= betweenDays; i++) {
|
| | |
| | | ChannelEnum[] channels = ChannelEnum.values();
|
| | | for (int i = 0; i < channels.length; i++) {
|
| | | Long count = userInfoRegisterService.countByChannelAndDay(channels[i].getVlaue(), preDay);
|
| | | BigDecimal total = new BigDecimal(0);
|
| | | if (count != null) {
|
| | | total = new BigDecimal(total.toString());
|
| | | if (count == null) {
|
| | | count = 0L;
|
| | | }
|
| | | DailyCountUser obj = new DailyCountUser();
|
| | | obj.setTotal(total);
|
| | | obj.setTotal(BigDecimal.valueOf(count));
|
| | | obj.setType(typeEnum);
|
| | | obj.setChannel(channels[i].name());
|
| | | obj.setUpdateDate(new Date());
|
| | |
| | | */
|
| | | private void addNewUserDownOrderDay(String preDay, DailyCountUserEnum typeEnum) throws Exception {
|
| | | // 统计当日有效订单
|
| | | List<CountOrderDTO> listOrder = commonOrderCountService.countValidOrderByDay(preDay);
|
| | | List<Long> listOrder = commonOrderCountService.getUidByValidOrderByDay(preDay);
|
| | | |
| | | // 查询当日新注册用户
|
| | | List<UserInfoRegister> listRegister = userInfoRegisterService.listByDay(preDay);
|
| | |
|
| | | ChannelEnum[] channels = ChannelEnum.values();
|
| | | for (int i = 0; i < channels.length; i++) {
|
| | | long totalDay = 0;
|
| | | long totalValid = 0;
|
| | | String channelName = channels[i].getVlaue();
|
| | |
|
| | | long totalUser = 0;
|
| | | long totalUserDown = 0;
|
| | | if (listOrder != null && listOrder.size() > 0) {
|
| | | // 查询该渠道当日注册用户
|
| | | List<UserInfoRegister> listRegister = userInfoRegisterService.listByChannelAndDay(channels[i].getVlaue(), preDay);
|
| | | if (listRegister != null && listRegister.size() > 0) {
|
| | | totalUser = listRegister.size();
|
| | | |
| | | // 循环统计是否存在用户下单
|
| | | for (UserInfoRegister userInfoRegister: listRegister) {
|
| | | Long id = userInfoRegister.getId();
|
| | | for (CountOrderDTO dto: listOrder) {
|
| | | if (dto.getUid() != null && dto.getUid().longValue() == id.longValue()) {
|
| | | totalUserDown ++;
|
| | | if (listOrder != null && listOrder.size() > 0 && listRegister != null && listRegister.size() > 0) {
|
| | | for (UserInfoRegister register: listRegister) {
|
| | | String channel = register.getChannel();
|
| | | if (channelName.equalsIgnoreCase(channel)) {
|
| | | // 当日渠道用户
|
| | | totalDay ++ ;
|
| | | |
| | | Long id = register.getId();
|
| | | // 判断当前用户是否今日下单
|
| | | for (Long uid: listOrder) {
|
| | | if (uid.longValue() == id.longValue()) {
|
| | | totalValid ++;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | // 计算比例: 下单用户数/新增用户数
|
| | | BigDecimal total = new BigDecimal(0);
|
| | | if (totalUser > 0 && totalUserDown > 0) {
|
| | | total = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalUserDown),BigDecimal.valueOf(totalUser));
|
| | | if (totalDay > 0 && totalValid > 0) {
|
| | | total = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalValid),BigDecimal.valueOf(totalDay));
|
| | | total = MoneyBigDecimalUtil.mul(total, BigDecimal.valueOf(100));
|
| | | }
|
| | |
|
| | | DailyCountUser obj = new DailyCountUser();
|
| | | obj.setTotal(total);
|
| | | obj.setRate(true);
|
| | | obj.setTotalDay(BigDecimal.valueOf(totalDay));
|
| | | obj.setTotalValid(BigDecimal.valueOf(totalValid));
|
| | | |
| | | obj.setType(typeEnum);
|
| | | obj.setChannel(channels[i].name());
|
| | | obj.setUpdateDate(new Date());
|
| | |
| | | long totalUser = 0;
|
| | | long totalWeek = 0;
|
| | | long totalWeek3 = 0;
|
| | | |
| | | List<Long> listUid = new ArrayList<Long>();
|
| | | |
| | | // 查询今日新增用户
|
| | | List<UserInfoRegister> list = userInfoRegisterService.listByChannelAndDay(channels[i].getVlaue(), preDay);
|
| | | |
| | | |
| | | if (list != null && list.size() > 0) {
|
| | | totalUser = list.size();
|
| | | for (UserInfoRegister user : list) {
|
| | | Integer total = commonOrderCountService.countOderByUidAndDate(limitDay, user.getId());
|
| | | if (total != null && total > 0) {
|
| | | totalWeek ++;
|
| | | listUid.add(user.getId());
|
| | | }
|
| | | }
|
| | | |
| | | if (listUid.size() > 0) {
|
| | | List<Long> listUidDown = commonOrderCountService.getDownOrderUserByListUidAndDate(limitDay, listUid);
|
| | | if (listUidDown != null && listUidDown.size() > 0) {
|
| | | for (Long uid: listUid) {
|
| | | int total = 0;
|
| | | for (Long id: listUidDown) {
|
| | | if (uid.longValue() == id.longValue()) {
|
| | | total ++;
|
| | | }
|
| | | }
|
| | | |
| | | if (total > 0) {
|
| | | totalWeek ++;
|
| | | }
|
| | | |
| | | if (total >= 3) {
|
| | | totalWeek3 ++;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | // 计算比例:当周 下单用户数/新增用户数
|
| | | BigDecimal total = new BigDecimal(0);
|
| | |
| | | total = MoneyBigDecimalUtil.mul(total, BigDecimal.valueOf(100));
|
| | | }
|
| | | DailyCountUser obj = new DailyCountUser();
|
| | | obj.setRate(true);
|
| | | obj.setTotalDay(BigDecimal.valueOf(totalUser));
|
| | | obj.setTotalValid(BigDecimal.valueOf(totalWeek));
|
| | | obj.setTotal(total);
|
| | | obj.setType(DailyCountUserEnum.newUserDownOrderWeek);
|
| | | obj.setChannel(channels[i].name());
|
| | |
| | | total3 = MoneyBigDecimalUtil.mul(total3, BigDecimal.valueOf(100));
|
| | | }
|
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setRate(true);
|
| | | obj3.setTotalDay(BigDecimal.valueOf(totalUser));
|
| | | obj3.setTotalValid(BigDecimal.valueOf(totalWeek3));
|
| | | obj3.setTotal(total3);
|
| | | obj3.setType(DailyCountUserEnum.newUserDownOrderWeek3);
|
| | | obj3.setChannel(channels[i].name());
|