| | |
| | | package com.yeshi.fanli.service.impl.count;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.yeshi.utils.DateUtil;
|
| | |
|
| | | import com.yeshi.fanli.dao.user.count.DailyCountUserDao;
|
| | | 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;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoRegister;
|
| | | import com.yeshi.fanli.entity.system.ChannelEnum;
|
| | | import com.yeshi.fanli.service.inter.count.DailyCountUserService;
|
| | | import com.yeshi.fanli.service.inter.money.extract.ExtractAuditRecordService;
|
| | | import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
|
| | | import com.yeshi.fanli.service.inter.redpack.RedPackDetailService;
|
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService;
|
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoRegisterService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | @Service
|
| | | public class DailyCountUserServiceImpl implements DailyCountUserService {
|
| | |
|
| | | @Resource
|
| | | private DailyCountUserDao dailyCountUserDao;
|
| | | |
| | | @Resource
|
| | | private UserInfoRegisterService userInfoRegisterService;
|
| | | |
| | | @Resource
|
| | | private CommonOrderCountService commonOrderCountService;
|
| | | |
| | | @Resource
|
| | | private UserActiveLogService userActiveLogService;
|
| | | |
| | | @Resource
|
| | | private IntegralDetailService integralDetailService;
|
| | | |
| | | @Resource
|
| | | private RedPackDetailService redPackDetailService;
|
| | | |
| | | @Resource
|
| | | private UserTaoLiJinDetailService userTaoLiJinDetailService;
|
| | | |
| | | @Resource
|
| | | private ExtractAuditRecordService extractAuditRecordService;
|
| | | |
| | |
|
| | | @Override
|
| | | public List<DailyCountUser> getDailyCountList(String type, Date startTime, Date endTime, String channel) throws Exception {
|
| | | // 查询类型
|
| | | DailyCountUserEnum typeEnum = getTypeEnum(type);
|
| | | if (typeEnum == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | // 初始化数据
|
| | | initData(typeEnum);
|
| | |
|
| | | return dailyCountUserDao.query(typeEnum, startTime, endTime, channel);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取枚举类型
|
| | | * @param type
|
| | | * @return
|
| | | */
|
| | | private DailyCountUserEnum getTypeEnum(String name) {
|
| | | if (StringUtil.isNullOrEmpty(name)) {
|
| | | return null;
|
| | | }
|
| | | |
| | | DailyCountUserEnum[] array = DailyCountUserEnum.values();
|
| | | for (int i = 0; i < array.length; i ++) {
|
| | | if (array[i].name().equals(name)) {
|
| | | return array[i];
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 获取枚举类型
|
| | | * @param type
|
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public String getTypeEnumDesc(String name) {
|
| | | if (StringUtil.isNullOrEmpty(name)) {
|
| | | return "";
|
| | | }
|
| | | |
| | | DailyCountUserEnum[] array = DailyCountUserEnum.values();
|
| | | for (int i = 0; i < array.length; i ++) {
|
| | | if (array[i].name().equals(name)) {
|
| | | return array[i].getDesc();
|
| | | }
|
| | | }
|
| | |
|
| | | return "";
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 初始数据
|
| | | * @param typeEnum
|
| | | * @throws Exception
|
| | | */
|
| | | @Override
|
| | | public void initData(DailyCountUserEnum typeEnum) throws Exception {
|
| | | Date lastDate = null;
|
| | | DailyCountUser lastRecord = dailyCountUserDao.getMaxDate(typeEnum);
|
| | | if (lastRecord != null) {
|
| | | lastDate = lastRecord.getUpdateDate();
|
| | | } 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++) {
|
| | | // 计算日期
|
| | | String preDay = DateUtil.plusDay(i, lastDate);
|
| | | // 统计数据
|
| | | if (DailyCountUserEnum.newUserChannel == typeEnum) {
|
| | | addNewUserChannel(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.newUserDownOrderDay == typeEnum) {
|
| | | addNewUserDownOrderDay(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.newUserDownOrderWeek == typeEnum) {
|
| | | addNewUserDownOrderWeek(preDay);
|
| | | } else if (DailyCountUserEnum.newUserDownOrderWeek3 == typeEnum) {
|
| | | addNewUserDownOrderWeek(preDay);
|
| | | } else if (DailyCountUserEnum.activeAgain90 == typeEnum) {
|
| | | addActiveAgain90(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.integralNum == typeEnum) {
|
| | | addIntegralNum(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.newUserTljNum == typeEnum) {
|
| | | addNewUserTljNum(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.newUserTljMoney == typeEnum) {
|
| | | addNewUserTljMoney(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.redpackNum == typeEnum) {
|
| | | addRedpackNum(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.redpackMoney == typeEnum) {
|
| | | addRedpackMoney(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.extractApplyNumber == typeEnum) {
|
| | | addExtractApplyNumber(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.extractApplyMoney == typeEnum) {
|
| | | addExtractApplyMoney(preDay, typeEnum);
|
| | | } else if (DailyCountUserEnum.extractAuditPass == typeEnum) {
|
| | | addExtractAuditNum(preDay, Extract.STATE_PASS, typeEnum);
|
| | | } else if (DailyCountUserEnum.extractAuditReject == typeEnum) {
|
| | | addExtractAuditNum(preDay, Extract.STATE_REJECT, typeEnum);
|
| | | } |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 统计各个渠道新增用户数量
|
| | | * @param preDay
|
| | | */
|
| | | private void addNewUserChannel(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | ChannelEnum[] channels = ChannelEnum.values();
|
| | | for (int i = 0; i < channels.length; i++) {
|
| | | Long count = userInfoRegisterService.countByChannelAndDay(channels[i].getVlaue(), preDay);
|
| | | if (count == null) {
|
| | | count = 0L;
|
| | | }
|
| | | DailyCountUser obj = new DailyCountUser();
|
| | | obj.setTotal(BigDecimal.valueOf(count));
|
| | | obj.setType(typeEnum);
|
| | | obj.setChannel(channels[i].name());
|
| | | obj.setUpdateDate(new Date());
|
| | | obj.setDay(TimeUtil.parse(preDay));
|
| | | obj.setId(StringUtil.Md5(preDay + channels[i].name() + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj);
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 统计各个渠道每日下单转化率
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addNewUserDownOrderDay(String preDay, DailyCountUserEnum typeEnum) throws Exception {
|
| | | // 统计当日有效订单
|
| | | 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();
|
| | | |
| | | 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 (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());
|
| | | obj.setDay(TimeUtil.parse(preDay));
|
| | | obj.setId(StringUtil.Md5(preDay + channels[i].name() + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 统计当周下单数据
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addNewUserDownOrderWeek(String preDay) throws Exception {
|
| | | // 加上6天 -注册一周内数据
|
| | | Date startDay = new Date(TimeUtil.convertDateToTemp2(preDay + " 23:59:59"));
|
| | | Date limitDay = DateUtil.plusDayDate(6, startDay);
|
| | | |
| | | // 渠道数据
|
| | | ChannelEnum[] channels = ChannelEnum.values();
|
| | | for (int i = 0; i < channels.length; i++) {
|
| | | 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) {
|
| | | 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);
|
| | | if (totalUser > 0 && totalWeek > 0) {
|
| | | total = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalWeek),BigDecimal.valueOf(totalUser));
|
| | | 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());
|
| | | obj.setUpdateDate(new Date());
|
| | | obj.setDay(TimeUtil.parse(preDay));
|
| | | obj.setId(StringUtil.Md5(preDay + channels[i].name() + DailyCountUserEnum.newUserDownOrderWeek.name()));
|
| | | dailyCountUserDao.save(obj);
|
| | | |
| | | |
| | | // 计算比例: 下3单用户数/新增用户数
|
| | | BigDecimal total3 = new BigDecimal(0);
|
| | | if (totalUser > 0 && totalWeek3 > 0) {
|
| | | total3 = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalWeek3),BigDecimal.valueOf(totalUser));
|
| | | 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());
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + channels[i].name() + DailyCountUserEnum.newUserDownOrderWeek3.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 统计90天内再次活跃
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addActiveAgain90(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | long count = userActiveLogService.count90DaysLaterActiveNum(preDay);
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(BigDecimal.valueOf(count));
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 金币新增数量
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addIntegralNum(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | Long count = integralDetailService.countNewAddByDate(preDay);
|
| | | if (count == null) {
|
| | | count = 0L;
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(BigDecimal.valueOf(count));
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | /**
|
| | | * 红包新增数量
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addRedpackNum(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | Long total = redPackDetailService.countNumByDay(preDay);
|
| | | if (total == null) {
|
| | | total = 0L;
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(new BigDecimal(total));
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 红包新增金额
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addRedpackMoney(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | BigDecimal total = redPackDetailService.countMoneyByDay(preDay);
|
| | | if (total == null) {
|
| | | total = new BigDecimal(0);
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(total);
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 红包新增数量
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addNewUserTljNum(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | Long total = userTaoLiJinDetailService.countNumByDay(preDay);
|
| | | if (total == null) {
|
| | | total = 0L;
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(new BigDecimal(total));
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 红包新增金额
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addNewUserTljMoney(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | BigDecimal total = userTaoLiJinDetailService.countMoneyByDay(preDay);
|
| | | if (total == null) {
|
| | | total = new BigDecimal(0);
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(total);
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 提现申请数量
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addExtractApplyNumber(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | Long total = extractAuditRecordService.countApplyNumberByDay(preDay);
|
| | | if (total == null) {
|
| | | total = 0L;
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(new BigDecimal(total));
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 提现申请金额
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addExtractApplyMoney(String preDay, DailyCountUserEnum typeEnum) throws Exception{
|
| | | BigDecimal total = extractAuditRecordService.countApplyMoneyByDay(preDay);
|
| | | if (total == null) {
|
| | | total = new BigDecimal(0);
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(total);
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | /**
|
| | | * 提现审核数量
|
| | | * @param preDay
|
| | | * @throws Exception
|
| | | */
|
| | | private void addExtractAuditNum(String preDay, int state, DailyCountUserEnum typeEnum) throws Exception{
|
| | | Long total = extractAuditRecordService.countAuditNumberByDay(state, preDay);
|
| | | if (total == null) {
|
| | | total = 0L;
|
| | | }
|
| | | |
| | | DailyCountUser obj3 = new DailyCountUser();
|
| | | obj3.setTotal(new BigDecimal(total));
|
| | | obj3.setType(typeEnum);
|
| | | obj3.setUpdateDate(new Date());
|
| | | obj3.setDay(TimeUtil.parse(preDay));
|
| | | obj3.setId(StringUtil.Md5(preDay + state + typeEnum.name()));
|
| | | dailyCountUserDao.save(obj3);
|
| | | }
|
| | | |
| | | |
| | | }
|
| | | package com.yeshi.fanli.service.impl.count; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.stereotype.Service; |
| | | import org.yeshi.utils.DateUtil; |
| | | |
| | | import com.yeshi.fanli.dao.user.count.DailyCountUserDao; |
| | | 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; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoRegister; |
| | | import com.yeshi.fanli.entity.system.ChannelEnum; |
| | | import com.yeshi.fanli.service.inter.count.DailyCountUserService; |
| | | import com.yeshi.fanli.service.inter.money.extract.ExtractAuditRecordService; |
| | | import com.yeshi.fanli.service.inter.order.CommonOrderCountService; |
| | | import com.yeshi.fanli.service.inter.redpack.RedPackDetailService; |
| | | import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinDetailService; |
| | | import com.yeshi.fanli.service.inter.user.UserActiveLogService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoRegisterService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService; |
| | | import org.yeshi.utils.MoneyBigDecimalUtil; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | @Service |
| | | public class DailyCountUserServiceImpl implements DailyCountUserService { |
| | | |
| | | @Resource |
| | | private DailyCountUserDao dailyCountUserDao; |
| | | |
| | | @Resource |
| | | private UserInfoRegisterService userInfoRegisterService; |
| | | |
| | | @Resource |
| | | private CommonOrderCountService commonOrderCountService; |
| | | |
| | | @Resource |
| | | private UserActiveLogService userActiveLogService; |
| | | |
| | | @Resource |
| | | private IntegralDetailService integralDetailService; |
| | | |
| | | @Resource |
| | | private RedPackDetailService redPackDetailService; |
| | | |
| | | @Resource |
| | | private UserTaoLiJinDetailService userTaoLiJinDetailService; |
| | | |
| | | @Resource |
| | | private ExtractAuditRecordService extractAuditRecordService; |
| | | |
| | | |
| | | @Override |
| | | public List<DailyCountUser> getDailyCountList(String type, Date startTime, Date endTime, String channel) throws Exception { |
| | | // 查询类型 |
| | | DailyCountUserEnum typeEnum = getTypeEnum(type); |
| | | if (typeEnum == null) { |
| | | return null; |
| | | } |
| | | |
| | | // 初始化数据 |
| | | initData(typeEnum); |
| | | |
| | | return dailyCountUserDao.query(typeEnum, startTime, endTime, channel); |
| | | } |
| | | |
| | | /** |
| | | * 获取枚举类型 |
| | | * @param type |
| | | * @return |
| | | */ |
| | | private DailyCountUserEnum getTypeEnum(String name) { |
| | | if (StringUtil.isNullOrEmpty(name)) { |
| | | return null; |
| | | } |
| | | |
| | | DailyCountUserEnum[] array = DailyCountUserEnum.values(); |
| | | for (int i = 0; i < array.length; i ++) { |
| | | if (array[i].name().equals(name)) { |
| | | return array[i]; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取枚举类型 |
| | | * @param type |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String getTypeEnumDesc(String name) { |
| | | if (StringUtil.isNullOrEmpty(name)) { |
| | | return ""; |
| | | } |
| | | |
| | | DailyCountUserEnum[] array = DailyCountUserEnum.values(); |
| | | for (int i = 0; i < array.length; i ++) { |
| | | if (array[i].name().equals(name)) { |
| | | return array[i].getDesc(); |
| | | } |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 初始数据 |
| | | * @param typeEnum |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void initData(DailyCountUserEnum typeEnum) throws Exception { |
| | | Date lastDate = null; |
| | | DailyCountUser lastRecord = dailyCountUserDao.getMaxDate(typeEnum); |
| | | if (lastRecord != null) { |
| | | lastDate = lastRecord.getUpdateDate(); |
| | | } 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++) { |
| | | // 计算日期 |
| | | String preDay = DateUtil.plusDay(i, lastDate); |
| | | // 统计数据 |
| | | if (DailyCountUserEnum.newUserChannel == typeEnum) { |
| | | addNewUserChannel(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.newUserDownOrderDay == typeEnum) { |
| | | addNewUserDownOrderDay(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.newUserDownOrderWeek == typeEnum) { |
| | | addNewUserDownOrderWeek(preDay); |
| | | } else if (DailyCountUserEnum.newUserDownOrderWeek3 == typeEnum) { |
| | | addNewUserDownOrderWeek(preDay); |
| | | } else if (DailyCountUserEnum.activeAgain90 == typeEnum) { |
| | | addActiveAgain90(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.integralNum == typeEnum) { |
| | | addIntegralNum(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.newUserTljNum == typeEnum) { |
| | | addNewUserTljNum(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.newUserTljMoney == typeEnum) { |
| | | addNewUserTljMoney(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.redpackNum == typeEnum) { |
| | | addRedpackNum(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.redpackMoney == typeEnum) { |
| | | addRedpackMoney(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.extractApplyNumber == typeEnum) { |
| | | addExtractApplyNumber(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.extractApplyMoney == typeEnum) { |
| | | addExtractApplyMoney(preDay, typeEnum); |
| | | } else if (DailyCountUserEnum.extractAuditPass == typeEnum) { |
| | | addExtractAuditNum(preDay, Extract.STATE_PASS, typeEnum); |
| | | } else if (DailyCountUserEnum.extractAuditReject == typeEnum) { |
| | | addExtractAuditNum(preDay, Extract.STATE_REJECT, typeEnum); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 统计各个渠道新增用户数量 |
| | | * @param preDay |
| | | */ |
| | | private void addNewUserChannel(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | ChannelEnum[] channels = ChannelEnum.values(); |
| | | for (int i = 0; i < channels.length; i++) { |
| | | Long count = userInfoRegisterService.countByChannelAndDay(channels[i].getVlaue(), preDay); |
| | | if (count == null) { |
| | | count = 0L; |
| | | } |
| | | DailyCountUser obj = new DailyCountUser(); |
| | | obj.setTotal(BigDecimal.valueOf(count)); |
| | | obj.setType(typeEnum); |
| | | obj.setChannel(channels[i].name()); |
| | | obj.setUpdateDate(new Date()); |
| | | obj.setDay(TimeUtil.parse(preDay)); |
| | | obj.setId(StringUtil.Md5(preDay + channels[i].name() + typeEnum.name())); |
| | | dailyCountUserDao.save(obj); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 统计各个渠道每日下单转化率 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addNewUserDownOrderDay(String preDay, DailyCountUserEnum typeEnum) throws Exception { |
| | | // 统计当日有效订单 |
| | | 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(); |
| | | |
| | | 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 (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()); |
| | | obj.setDay(TimeUtil.parse(preDay)); |
| | | obj.setId(StringUtil.Md5(preDay + channels[i].name() + typeEnum.name())); |
| | | dailyCountUserDao.save(obj); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 统计当周下单数据 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addNewUserDownOrderWeek(String preDay) throws Exception { |
| | | // 加上6天 -注册一周内数据 |
| | | Date startDay = new Date(TimeUtil.convertDateToTemp2(preDay + " 23:59:59")); |
| | | Date limitDay = DateUtil.plusDayDate(6, startDay); |
| | | |
| | | // 渠道数据 |
| | | ChannelEnum[] channels = ChannelEnum.values(); |
| | | for (int i = 0; i < channels.length; i++) { |
| | | 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) { |
| | | 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); |
| | | if (totalUser > 0 && totalWeek > 0) { |
| | | total = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalWeek),BigDecimal.valueOf(totalUser)); |
| | | 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()); |
| | | obj.setUpdateDate(new Date()); |
| | | obj.setDay(TimeUtil.parse(preDay)); |
| | | obj.setId(StringUtil.Md5(preDay + channels[i].name() + DailyCountUserEnum.newUserDownOrderWeek.name())); |
| | | dailyCountUserDao.save(obj); |
| | | |
| | | |
| | | // 计算比例: 下3单用户数/新增用户数 |
| | | BigDecimal total3 = new BigDecimal(0); |
| | | if (totalUser > 0 && totalWeek3 > 0) { |
| | | total3 = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalWeek3),BigDecimal.valueOf(totalUser)); |
| | | 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()); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + channels[i].name() + DailyCountUserEnum.newUserDownOrderWeek3.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 统计90天内再次活跃 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addActiveAgain90(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | long count = userActiveLogService.count90DaysLaterActiveNum(preDay); |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(BigDecimal.valueOf(count)); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 金币新增数量 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addIntegralNum(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | Long count = integralDetailService.countNewAddByDate(preDay); |
| | | if (count == null) { |
| | | count = 0L; |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(BigDecimal.valueOf(count)); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | /** |
| | | * 红包新增数量 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addRedpackNum(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | Long total = redPackDetailService.countNumByDay(preDay); |
| | | if (total == null) { |
| | | total = 0L; |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(new BigDecimal(total)); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 红包新增金额 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addRedpackMoney(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | BigDecimal total = redPackDetailService.countMoneyByDay(preDay); |
| | | if (total == null) { |
| | | total = new BigDecimal(0); |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(total); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 红包新增数量 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addNewUserTljNum(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | Long total = userTaoLiJinDetailService.countNumByDay(preDay); |
| | | if (total == null) { |
| | | total = 0L; |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(new BigDecimal(total)); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 红包新增金额 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addNewUserTljMoney(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | BigDecimal total = userTaoLiJinDetailService.countMoneyByDay(preDay); |
| | | if (total == null) { |
| | | total = new BigDecimal(0); |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(total); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提现申请数量 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addExtractApplyNumber(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | Long total = extractAuditRecordService.countApplyNumberByDay(preDay); |
| | | if (total == null) { |
| | | total = 0L; |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(new BigDecimal(total)); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 提现申请金额 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addExtractApplyMoney(String preDay, DailyCountUserEnum typeEnum) throws Exception{ |
| | | BigDecimal total = extractAuditRecordService.countApplyMoneyByDay(preDay); |
| | | if (total == null) { |
| | | total = new BigDecimal(0); |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(total); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | /** |
| | | * 提现审核数量 |
| | | * @param preDay |
| | | * @throws Exception |
| | | */ |
| | | private void addExtractAuditNum(String preDay, int state, DailyCountUserEnum typeEnum) throws Exception{ |
| | | Long total = extractAuditRecordService.countAuditNumberByDay(state, preDay); |
| | | if (total == null) { |
| | | total = 0L; |
| | | } |
| | | |
| | | DailyCountUser obj3 = new DailyCountUser(); |
| | | obj3.setTotal(new BigDecimal(total)); |
| | | obj3.setType(typeEnum); |
| | | obj3.setUpdateDate(new Date()); |
| | | obj3.setDay(TimeUtil.parse(preDay)); |
| | | obj3.setId(StringUtil.Md5(preDay + state + typeEnum.name())); |
| | | dailyCountUserDao.save(obj3); |
| | | } |
| | | |
| | | |
| | | } |