From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/count/UserInfoCountServiceImpl.java | 1171 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 1,002 insertions(+), 169 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/count/UserInfoCountServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/count/UserInfoCountServiceImpl.java index acafb88..4f9b0cf 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/count/UserInfoCountServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/count/UserInfoCountServiceImpl.java @@ -1,169 +1,1002 @@ -package com.yeshi.fanli.service.impl.count; - - -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Service; -import org.yeshi.utils.DateUtil; - -import com.yeshi.fanli.dao.mybatis.UserInfoMapper; -import com.yeshi.fanli.service.inter.count.UserInfoCountService; - -@Service -public class UserInfoCountServiceImpl implements UserInfoCountService { - - @Resource - private UserInfoMapper userInfoMapper; - - - @Override - public long countNewUser(Integer isToday, Integer isMonth) { - return userInfoMapper.countNewUser(isToday, isMonth); - } - - @Override - public long countRank(Integer rank) { - return userInfoMapper.countRank(rank); - } - - @Override - public BigDecimal countAllMoney(Double rank) { - return userInfoMapper.countAllMoney(rank); - } - - - @Override - public long countLoseUser(int daysNum) { - return userInfoMapper.countLoseUser(daysNum); - } - - @Override - public long countHasOrderUser() { - return userInfoMapper.countHasOrderUser(); - } - - public List<Map<String, Object>> countNewUserByDate(Integer type,String years, String startTime, - String endTime) throws Exception { - return userInfoMapper.countNewUserByDate(type, years, startTime, endTime); - - } - - - public List<Object> dayFactory(String startTime, String endTime, List<Map<String, Object>> list) throws Exception { - - List<Object> listObject = new ArrayList<Object>(); - - if (startTime.equals(endTime)) { - - Map<String, Object> map = list.get(0); - Object total = map.get("total"); - if (total == null) { - map.put("payMoney", 0); - } - listObject.add(map); - return listObject; - } - - - String plusDay = ""; - for (int i = 0; i < 1000 ; i++) { - if (i == 0) { - plusDay = startTime; - } else { - plusDay = DateUtil.plusDay(i, startTime); - } - - Map<String, Object> mapObject = new HashMap<String, Object>(); - Object total = null; - - for (int j = 0; j < list.size(); j++) { - Map<String, Object> map = list.get(j); - Object createDate = map.get("createDate"); - String month = createDate.toString(); - if (plusDay.equalsIgnoreCase(month)) { - total = map.get("total"); - break; - } - } - - if (total == null) { - total = 0; - } - mapObject.put("total", total); - - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd"); - Date parseDate = sdf.parse(plusDay.toString()); - - mapObject.put("createDate", sdf2.format(parseDate)); - - listObject.add(mapObject); - - if (plusDay.equals(endTime)) { - break; // 鏃堕棿缁撴潫 - } - } - - return listObject; - } - - - public List<Object> monthFactory(List<Map<String, Object>> list) { - - List<Object> listObject = new ArrayList<Object>(); - // 12 涓湀澶勭悊 - for (int i = 1; i <= 12; i++) { - Map<String, Object> mapObject = new HashMap<String, Object>(); - Object total = null; - - for (int j = 0; j < list.size(); j++) { - Map<String, Object> map = list.get(j); - Object createDate = map.get("createDate"); - String month = createDate.toString(); - if ((i+"").equalsIgnoreCase(month) || i == Integer.parseInt(month)) { - total = map.get("total"); - break; - } - } - - if (total == null) { - total = 0; - } - mapObject.put("total", total); - - mapObject.put("createDate", i + "鏈�"); - - listObject.add(mapObject); - } - return listObject; - } - - public List<Object> yearFactory(List<Map<String, Object>> list) { - - List<Object> listObject = new ArrayList<Object>(); - - for (int i = 0; i < list.size(); i++) { - Map<String, Object> map = list.get(i); - Object total = map.get("total"); - - if (total == null) { - total = 0; - } - map.put("total", total); - - listObject.add(map); - } - - return listObject; - } - - -} +package com.yeshi.fanli.service.impl.count; + +import java.math.BigDecimal; +import java.text.DecimalFormat; +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.mybatis.UserInfoCountMapper; +import com.yeshi.fanli.dao.mybatis.UserInfoMapper; +import com.yeshi.fanli.dao.user.count.CountOrderInfoDao; +import com.yeshi.fanli.dao.user.count.CountUserInfoDao; +import com.yeshi.fanli.dto.ChartTDO; +import com.yeshi.fanli.dto.order.CountOrderDTO; +import com.yeshi.fanli.entity.admin.count.CountOrderInfo; +import com.yeshi.fanli.entity.admin.count.CountOrderInfo.CountOrderEnum; +import com.yeshi.fanli.entity.admin.count.CountUserInfo; +import com.yeshi.fanli.entity.admin.count.CountUserInfo.CountUserEnum; +import com.yeshi.fanli.entity.bus.user.UserInfoRegister; +import com.yeshi.fanli.entity.system.ChannelEnum; +import com.yeshi.fanli.service.inter.count.HongBaoV2CountService; +import com.yeshi.fanli.service.inter.count.UserInfoCountService; +import com.yeshi.fanli.service.inter.order.CommonOrderCountService; +import com.yeshi.fanli.service.inter.order.LostOrderService; +import com.yeshi.fanli.service.inter.order.UserOrderWeiQuanRecordService; +import com.yeshi.fanli.service.inter.user.UserInfoRegisterService; +import org.yeshi.utils.MoneyBigDecimalUtil; +import com.yeshi.fanli.util.StringUtil; +import org.yeshi.utils.TimeUtil; +import com.yeshi.fanli.vo.user.UserGoldCoinVO; + +@Service +public class UserInfoCountServiceImpl implements UserInfoCountService { + + @Resource + private UserInfoMapper userInfoMapper; + + @Resource + private UserInfoCountMapper userInfoCountMapper; + + @Resource + private CountUserInfoDao countUserInfoDao; + + @Resource + private CountOrderInfoDao countOrderInfoDao; + + @Resource + private CommonOrderCountService commonOrderCountService; + + @Resource + private HongBaoV2CountService hongBaoV2CountService; + + @Resource + private UserOrderWeiQuanRecordService userOrderWeiQuanRecordService; + + @Resource + private LostOrderService lostOrderService; + + @Resource + private UserInfoRegisterService userInfoRegisterService; + + + @Override + public long countNewUser(Integer isToday, Integer isMonth) { + return userInfoMapper.countNewUser(isToday, isMonth); + } + + @Override + public long countRank(Integer rank) { + return userInfoMapper.countRank(rank); + } + + @Override + public BigDecimal countAllMoney(Double rank) { + return userInfoMapper.countAllMoney(rank); + } + + @Override + public long countLoseUser(int daysNum) { + return userInfoMapper.countLoseUser(daysNum); + } + + @Override + public long countHasOrderUser() { + return userInfoMapper.countHasOrderUser(); + } + + @Override + public List<ChartTDO> countNewUserByDate(String channel, Integer type, String years, String startTime, + String endTime) throws Exception { + return userInfoMapper.countNewUserByDate(channel, type, years, startTime, endTime); + + } + + @Override + public List<ChartTDO> getTodayBuyRate(String channel, Integer dateType, String years, String startTime, + String endTime) throws Exception { + + List<ChartTDO> result_list = null; + + List<ChartTDO> listToday = userInfoMapper.getTodayHasOrder(channel, dateType, years, startTime, endTime); + + if (listToday == null || listToday.size() == 0) { + return result_list; + } + + List<ChartTDO> listTotal = userInfoMapper.countNewUserByDate(channel, dateType, years, startTime, endTime); + + if (listTotal == null || listTotal.size() == 0) { + return result_list; + } + + switch (dateType) { + case 1: // 鎸夊ぉ澶勭悊 + result_list = dayFactory(startTime, endTime, listTotal); + break; + case 2: // 鎸夋湀澶勭悊 + result_list = monthFactory(listTotal); + break; + case 3: + result_list = yearFactory(listTotal); + break; + default: + break; + } + + DecimalFormat df = new DecimalFormat("#.00"); + + for (int i = 0; i < result_list.size(); i++) { + double proportion = 0; + ChartTDO chartTDO = result_list.get(i); + String showDate = chartTDO.getShowDate(); + for (int j = 0; j < listToday.size(); j++) { + ChartTDO innerTDO = listToday.get(j); + String innerDate = innerTDO.getShowDate(); + if (innerDate != null && innerDate.equals(showDate)) { + String innerValue = innerTDO.getShowValue(); + long innerData = Long.parseLong(innerValue); + + String showValue = chartTDO.getShowValue(); + long showData = Long.parseLong(showValue); + + if (showData > 0) { + proportion = innerData / (double) showData; + } + break; // 缁撴潫鍐呴儴寰幆 + } + } + chartTDO.setShowValue(Double.parseDouble(df.format(proportion * 100)) + ""); + } + return result_list; + } + + @Override + public List<Object> getWeekBuyRate(String channel, String startTime, String endTime, Integer orderNum, + List<String> dateList) throws Exception { + List<Object> resultList = new ArrayList<Object>(); + if (dateList == null || dateList.size() == 0) { + return resultList; + } + + List<ChartTDO> totalList = userInfoMapper.countNewUserByDate(channel, 1, null, startTime, endTime); + if (totalList == null || totalList.size() == 0) { + return resultList; + } + + DecimalFormat df = new DecimalFormat("#.00"); + for (int i = 0; i < dateList.size(); i++) { + double proportion = 0; + String showDate = dateList.get(i); + String plusDay = DateUtil.plusDay(7, showDate); + ChartTDO chartTDO = userInfoMapper.getWeekHasOrder(channel, showDate, plusDay, orderNum); + + String showValue = null; + if (chartTDO != null) { + showValue = chartTDO.getShowValue(); + if (showValue != null) { + for (int j = 0; j < totalList.size(); j++) { + ChartTDO chart = totalList.get(j); + String reslutTime = chart.getShowDate(); + if (showDate.equalsIgnoreCase(reslutTime)) { + String totalObject = chart.getShowValue(); + long hasCount = Long.parseLong(showValue); + long total = Long.parseLong(totalObject); + + if (total > 0) { + proportion = hasCount / (double) total; + } + + break; + } + } + } + } + resultList.add(Double.parseDouble(df.format(proportion * 100))); + } + + return resultList; + } + + public List<ChartTDO> dayFactory(String startTime, String endTime, List<ChartTDO> list) throws Exception { + List<ChartTDO> listObject = new ArrayList<ChartTDO>(); + if (startTime.equals(endTime)) { + ChartTDO chartTDO = list.get(0); + String showValue = chartTDO.getShowValue(); + if (showValue == null) { + chartTDO.setShowValue("0"); + } + listObject.add(chartTDO); + return listObject; + } + + String plusDay = ""; + for (int i = 0; i < 1000; i++) { + if (i == 0) { + plusDay = startTime; + } else { + plusDay = DateUtil.plusDay(i, startTime); + } + + String total = null; + for (int j = 0; j < list.size(); j++) { + ChartTDO chartTDO = list.get(j); + String month = chartTDO.getShowDate(); + if (plusDay.equalsIgnoreCase(month)) { + total = chartTDO.getShowValue(); + break; + } + } + + if (total == null) { + total = "0"; + } + ChartTDO chartTDO = new ChartTDO(); + chartTDO.setShowValue(total); + chartTDO.setShowDate(plusDay); + listObject.add(chartTDO); + + if (plusDay.equals(endTime)) { + break; // 鏃堕棿缁撴潫 + } + } + + return listObject; + } + + public List<ChartTDO> monthFactory(List<ChartTDO> list) { + List<ChartTDO> listObject = new ArrayList<ChartTDO>(); + // 12 涓湀澶勭悊 + for (int i = 1; i <= 12; i++) { + String total = null; + for (int j = 0; j < list.size(); j++) { + ChartTDO chartTDO = list.get(j); + String month = chartTDO.getShowDate(); + if ((i + "").equalsIgnoreCase(month) || i == Integer.parseInt(month)) { + total = chartTDO.getShowValue(); + break; + } + } + + if (total == null) { + total = "0"; + } + + ChartTDO chartTDO = new ChartTDO(); + chartTDO.setShowValue(total); + + if (i < 10) { + chartTDO.setShowDate("0" + i); + } else { + chartTDO.setShowDate("" + i); + } + listObject.add(chartTDO); + } + return listObject; + } + + public List<ChartTDO> yearFactory(List<ChartTDO> list) { + List<ChartTDO> listObject = new ArrayList<ChartTDO>(); + for (int i = 0; i < list.size(); i++) { + ChartTDO chartTDO = list.get(i); + String total = chartTDO.getShowValue(); + if (total == null) { + total = "0"; + } + chartTDO.setShowValue(total); + listObject.add(chartTDO); + } + return listObject; + } + + @Override + public List<UserGoldCoinVO> listByUserGoldCoin(long start, int count, int type, String key) { + return userInfoCountMapper.listByUserGoldCoin(start, count, type, key); + } + + @Override + public long countByUserGoldCoin(int type, String key) { + return userInfoCountMapper.countByUserGoldCoin(type, key); + } + + @Override + public List<UserGoldCoinVO> listByHasGoldCoin(long start, int count, String key) { + return userInfoCountMapper.listByHasGoldCoin(start, count, key); + } + + @Override + public long countByHasGoldCoin(String key) { + return userInfoCountMapper.countByHasGoldCoin(key); + } + + @Override + public List<CountUserInfo> getNewUserData(Date startTime, Date endTime, String channel) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + + return countUserInfoDao.query(CountUserEnum.newUser, startTime, endTime, channel); + } + + + + + @Override + public List<CountOrderInfo> countOderByChannel(String channel, Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initOrderCount(); + + return countOrderInfoDao.query(CountOrderEnum.channelTotal, startTime, endTime, channel); + } + + // 鍒濆鍖栫粺璁� + private void initOrderCount() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.channelTotal); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2018-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordOrderCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordOrderCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordOrderCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + private void addRecordOrderCount(String preDay) throws Exception { + ChannelEnum[] channels = ChannelEnum.values(); + for (int i = 0; i < channels.length; i++) { + int count = 0; + String channelVlaue = channels[i].getVlaue(); + + List<CountOrderDTO> listOrder = commonOrderCountService.countValidOrderByDay(preDay); + if (listOrder != null && listOrder.size() > 0) { + List<Long> listUid = new ArrayList<>(); + for (CountOrderDTO countOrderDTO: listOrder) { + listUid.add(countOrderDTO.getUid()); + } + + List<UserInfoRegister> listRegister = userInfoRegisterService.listByMultipleUids(listUid); + if (listRegister != null && listRegister.size() > 0) { + for (int m = 0; m <listRegister.size(); m ++) { + boolean reduce = false; + Long uid = listRegister.get(m).getId(); + String vlaue = listRegister.get(m).getChannel(); + + for (int n = 0; n <listOrder.size(); n ++) { + if (channelVlaue.equalsIgnoreCase(vlaue) && uid.longValue() == listOrder.get(n).getUid()) { + Integer totalOrder = listOrder.get(n).getTotalOrder(); + if (totalOrder != null) + count += totalOrder; + + listOrder.remove(n); + n--; + reduce = true; + } + } + + if (reduce) { + listRegister.remove(m); + m--; + } + } + } + } + + CountOrderInfo record = new CountOrderInfo(); + record.setNum(count); + record.setChannel(channels[i].name()); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.channelTotal.name()); + record.setId(StringUtil.Md5(preDay + channels[i].name() + CountOrderEnum.channelTotal.name())); + countOrderInfoDao.save(record); + } + } + + + @Override + public List<CountOrderInfo> count24HOderByChannel(String channel, Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + init24HOrderCount(); + + return countOrderInfoDao.query(CountOrderEnum.oder24H, startTime, endTime, channel); + } + + // 鍒濆鍖栫粺璁� + private void init24HOrderCount() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.oder24H); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2018-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecord24HOrderCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecord24HOrderCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecord24HOrderCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecord24HOrderCount(String preDay) throws Exception { + ChannelEnum[] channels = ChannelEnum.values(); + for (int i = 0; i < channels.length; i++) { + int count = 0; + List<UserInfoRegister> list = userInfoRegisterService.listByChannelAndDay(channels[i].getVlaue(), preDay); + if (list != null && list.size() > 0) { + // 缁熻24灏忔椂浜х敓璁㈠崟鏁伴噺 + for (UserInfoRegister user : list) { + Date limitDay = DateUtil.plusDayDate(1, user.getCreateTime()); + Integer total = commonOrderCountService.countOderByUidAndDate(limitDay, user.getId()); + if (total != null) + count += total; + } + } + CountOrderInfo record = new CountOrderInfo(); + record.setNum(count); + record.setChannel(channels[i].name()); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.oder24H.name()); + record.setId(StringUtil.Md5(preDay + channels[i].name() + CountOrderEnum.oder24H.name())); + countOrderInfoDao.save(record); + } + } + + + @Override + public List<CountOrderInfo> countHongBaoByChannel(String channel, Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initHongBaoCount(); + + return countOrderInfoDao.query(CountOrderEnum.channelCommission, startTime, endTime, channel); + } + + // 鍒濆鍖栫粺璁� + private void initHongBaoCount() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.channelCommission); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2018-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordHongBaoCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordHongBaoCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordHongBaoCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordHongBaoCount(String preDay) throws Exception { + ChannelEnum[] channels = ChannelEnum.values(); + for (int i = 0; i < channels.length; i++) { + BigDecimal money = new BigDecimal(0); + String channelVlaue = channels[i].getVlaue(); + + List<CountOrderDTO> listOrder = commonOrderCountService.countCommissionByDay(preDay); + if (listOrder != null && listOrder.size() > 0) { + List<Long> listUid = new ArrayList<>(); + for (CountOrderDTO countOrderDTO: listOrder) { + listUid.add(countOrderDTO.getUid()); + } + + List<UserInfoRegister> listRegister = userInfoRegisterService.listByMultipleUids(listUid); + if (listRegister != null && listRegister.size() > 0) { + for (int m = 0; m <listRegister.size(); m ++) { + boolean reduce = false; + Long uid = listRegister.get(m).getId(); + String vlaue = listRegister.get(m).getChannel(); + + for (int n = 0; n <listOrder.size(); n ++) { + if (channelVlaue.equalsIgnoreCase(vlaue) && uid.longValue() == listOrder.get(n).getUid()) { + BigDecimal commission = listOrder.get(n).getCommission(); + if (commission != null) + MoneyBigDecimalUtil.add(money, commission); + + listOrder.remove(n); + n--; + reduce = true; + } + } + + if (reduce) { + listRegister.remove(m); + m--; + } + } + } + } + + + CountOrderInfo record = new CountOrderInfo(); + record.setMoney(money); + record.setChannel(channels[i].name()); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.channelCommission.name()); + record.setId(StringUtil.Md5(preDay + channels[i].name() + CountOrderEnum.channelCommission.name())); + countOrderInfoDao.save(record); + } + } + + + @Override + public List<CountOrderInfo> countWeiQuanOrder(Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initWeiQuanCount(); + + return countOrderInfoDao.query(CountOrderEnum.weiQuanNum, startTime, endTime); + } + + // 鍒濆鍖栫粺璁� + private void initWeiQuanCount() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.weiQuanNum); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2019-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordWeiQuanCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordWeiQuanCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordWeiQuanCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordWeiQuanCount(String preDay) throws Exception { + Integer count = userOrderWeiQuanRecordService.countWeiQaunOrderNumberByDate(preDay); + if (count == null) + count = 0; + CountOrderInfo record = new CountOrderInfo(); + record.setNum(count); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.weiQuanNum.name()); + record.setId(StringUtil.Md5(preDay + CountOrderEnum.weiQuanNum.name())); + countOrderInfoDao.save(record); + } + + + @Override + public List<CountOrderInfo> countWeiQuanOrderMoney(Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initWeiQuanMoneyCount(); + + return countOrderInfoDao.query(CountOrderEnum.weiQuanMoney, startTime, endTime); + } + + // 鍒濆鍖栫粺璁� + private void initWeiQuanMoneyCount() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.weiQuanMoney); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2019-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordWeiQuanMoneyCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordWeiQuanMoneyCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordWeiQuanMoneyCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordWeiQuanMoneyCount(String preDay) throws Exception { + BigDecimal money = userOrderWeiQuanRecordService.countWeiQaunOrderMoneyByDate(preDay); + if (money == null) + money = new BigDecimal(0); + CountOrderInfo record = new CountOrderInfo(); + record.setMoney(money); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.weiQuanMoney.name()); + record.setId(StringUtil.Md5(preDay + CountOrderEnum.weiQuanMoney.name())); + countOrderInfoDao.save(record); + } + + + @Override + public List<CountOrderInfo> counOrderTotalNum(Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initOrderTotalNum(); + + return countOrderInfoDao.query(CountOrderEnum.totalNum, startTime, endTime); + } + + // 鍒濆鍖栫粺璁� + private void initOrderTotalNum() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.totalNum); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2019-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordOrderTotalNum(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordOrderTotalNum(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordOrderTotalNum(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordOrderTotalNum(String preDay) throws Exception { + Integer num = commonOrderCountService.countOderByDate(preDay); + if (num == null) + num = 0; + CountOrderInfo record = new CountOrderInfo(); + record.setNum(num); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.totalNum.name()); + record.setId(StringUtil.Md5(preDay + CountOrderEnum.totalNum.name())); + countOrderInfoDao.save(record); + } + + + + + @Override + public List<CountOrderInfo> counOrderTotalCommission(Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initTotalCommission(); + + return countOrderInfoDao.query(CountOrderEnum.totalCommission, startTime, endTime); + } + + // 鍒濆鍖栫粺璁� + private void initTotalCommission() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.totalCommission); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2019-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordTotalCommission(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordTotalCommission(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordTotalCommission(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordTotalCommission(String preDay) throws Exception { + BigDecimal money = commonOrderCountService.countCommissionByDate(preDay); + if (money == null) + money = new BigDecimal("0"); + CountOrderInfo record = new CountOrderInfo(); + record.setMoney(money); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.totalCommission.name()); + record.setId(StringUtil.Md5(preDay + CountOrderEnum.totalCommission.name())); + countOrderInfoDao.save(record); + } + + @Override + public List<CountOrderInfo> counOrderLastNum(Date startTime, Date endTime) { + + return countOrderInfoDao.query(CountOrderEnum.lastNum, startTime, endTime); + } + + + + @Override + public List<CountOrderInfo> counOrderLastMoney(Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initOrderLastMoney(); + + return countOrderInfoDao.query(CountOrderEnum.lastMoney, startTime, endTime); + } + + // 鍒濆鍖栫粺璁� + private void initOrderLastMoney() { + try { + CountOrderInfo lastRecord = countOrderInfoDao.getMaxDate(CountOrderEnum.lastMoney); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + + if (lastDay == null) { + lastDay = TimeUtil.parse("2019-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordOrderLastMoney(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordOrderLastMoney(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordOrderLastMoney(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordOrderLastMoney(String preDay) throws Exception { + BigDecimal money = lostOrderService.countAppealMoney(preDay); + if (money == null) + money = new BigDecimal("0"); + CountOrderInfo record = new CountOrderInfo(); + record.setMoney(money); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountOrderEnum.lastMoney.name()); + record.setId(StringUtil.Md5(preDay + CountOrderEnum.lastMoney.name())); + countOrderInfoDao.save(record); + } + + + + + @Override + public List<CountUserInfo> countUserDownOrderByChannelAndToday(String channel, Date startTime, Date endTime) { + // 閲嶆柊鏌ヨ缁熻浠婃棩浠ュ強绌虹己 + initTodayDownOrderCount(); + + return countUserInfoDao.query(CountUserEnum.todayOrder, startTime, endTime, channel); + } + + // 鍒濆鍖栫粺璁� + private void initTodayDownOrderCount() { + try { + CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.todayOrder); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + if (lastDay == null) { + lastDay = TimeUtil.parse("2018-01-01"); + } + + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordTodayDownOrderCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordTodayDownOrderCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordTodayDownOrderCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordTodayDownOrderCount(String preDay) throws Exception { + ChannelEnum[] channels = ChannelEnum.values(); + for (int i = 0; i < channels.length; i++) { + int count = 0; + String channelVlaue = channels[i].getVlaue(); + + List<CountOrderDTO> listOrder = commonOrderCountService.countValidOrderByDay(preDay); + if (listOrder != null && listOrder.size() > 0) { + List<Long> listUid = new ArrayList<>(); + for (CountOrderDTO countOrderDTO: listOrder) { + listUid.add(countOrderDTO.getUid()); + } + + List<UserInfoRegister> listRegister = userInfoRegisterService.listByMultipleUidAndDay(listUid, preDay); + if (listRegister != null && listRegister.size() > 0) { + for (int m = 0; m <listRegister.size(); m ++) { + boolean reduce = false; + Long uid = listRegister.get(m).getId(); + String vlaue = listRegister.get(m).getChannel(); + + for (int n = 0; n <listOrder.size(); n ++) { + if (channelVlaue.equalsIgnoreCase(vlaue) && uid.longValue() == listOrder.get(n).getUid()) { + Integer totalOrder = listOrder.get(n).getTotalOrder(); + if (totalOrder != null) + count += totalOrder; + + listOrder.remove(n); + n--; + reduce = true; + } + } + + if (reduce) { + listRegister.remove(m); + m--; + } + } + } + } + + CountUserInfo record = new CountUserInfo(); + record.setNum(count); + record.setChannel(channels[i].name()); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountUserEnum.todayOrder); + record.setId(StringUtil.Md5(preDay + channels[i].name() + CountUserEnum.todayOrder.name())); + countUserInfoDao.save(record); + } + } + + @Override + public List<CountUserInfo> countUseByChannelAndWeekOrder(String channel, Date startTime, Date endTime) { + return countUserInfoDao.query(CountUserEnum.weekOrder, startTime, endTime, channel); + } + + @Override + public List<CountUserInfo> countUseByChannelAndWeekThreeOrder(String channel, Date startTime, Date endTime) { + return countUserInfoDao.query(CountUserEnum.weekThreeOrder, startTime, endTime, channel); + } + + // 鍒濆鍖栫粺璁� + @Override + public void initCountUserWeekOrder() { + try { + CountUserInfo lastRecord = countUserInfoDao.getMaxDate(CountUserEnum.weekOrder); + Date lastDay = null; + if (lastRecord != null && lastRecord.getDay() != null) { + lastDay = lastRecord.getDay(); + } + if (lastDay == null) { + lastDay = TimeUtil.parse("2018-01-01"); + } + Date today = new Date(); + int betweenDays = DateUtil.daysBetween2(lastDay, today); + if (betweenDays > 0) { + for (int i = 0; i <= betweenDays; i++) { + addRecordWeekOrderCount(DateUtil.plusDay(i, lastDay)); + } + } else { + // 閲嶆柊缁熻鏄ㄦ棩 + addRecordWeekOrderCount(DateUtil.reduceDay2(1, lastDay)); + // 閲嶆柊缁熻浠婃棩 + addRecordWeekOrderCount(TimeUtil.getGernalTime(today.getTime())); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void addRecordWeekOrderCount(String preDay) throws Exception { + ChannelEnum[] channels = ChannelEnum.values(); + for (int i = 0; i < channels.length; i++) { + int count = 0; + int count3 = 0; + List<UserInfoRegister> list = userInfoRegisterService.listByChannelAndDay(channels[i].getVlaue(), preDay); + if (list != null && list.size() > 0) { + Date startDay = new Date(TimeUtil.convertDateToTemp2(preDay + " 23:59:59")); + Date limitDay = DateUtil.plusDayDate(6, startDay); + for (UserInfoRegister user : list) { + Integer total = commonOrderCountService.countOderByUidAndDate(limitDay, user.getId()); + if (total != null && total > 0) { + count++; + if (total >= 3) { + count3++; + } + } + } + } + + // 7澶╁唴浜х敓鏈夋晥璁㈠崟 + CountUserInfo record = new CountUserInfo(); + record.setNum(count); + record.setChannel(channels[i].name()); + record.setDay(TimeUtil.parse(preDay)); + record.setType(CountUserEnum.weekOrder); + record.setId(StringUtil.Md5(preDay + channels[i].name() + CountUserEnum.weekOrder.name())); + countUserInfoDao.save(record); + + // 7澶╁唴浜х敓3鍗曚互涓婃湁鏁堣鍗� + CountUserInfo record3 = new CountUserInfo(); + record3.setNum(count3); + record3.setChannel(channels[i].name()); + record3.setDay(TimeUtil.parse(preDay)); + record3.setType(CountUserEnum.weekThreeOrder); + record3.setId(StringUtil.Md5(preDay + channels[i].name() + CountUserEnum.weekThreeOrder.name())); + countUserInfoDao.save(record); + } + } + +} -- Gitblit v1.8.0