|
|
|
@@ -38,8 +38,102 @@ import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class WxChartServiceImpl implements WxChartDataService { |
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
WxChartDataMapper wxChartDataMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData queryWeekCount(EnumChartType chartType, TenantEntity tenantEntity) { |
|
|
|
Date now = new Date(); |
|
|
|
String weekStartdate = DateUtils.getTimeBefore(7, now); |
|
|
|
String yesterdayDate = DateUtils.getTimeBefore(1, now); |
|
|
|
WxChartDataEntity ChartDataEntity = new WxChartDataEntity(); |
|
|
|
ChartDataEntity.updateTenantInfo(tenantEntity); |
|
|
|
ChartDataEntity.setType(chartType.getCode()); |
|
|
|
ChartDataEntity.setStartTime(DateUtils.stringToDate(yesterdayDate)); |
|
|
|
Long yesterdayCount = wxChartDataMapper.findSumResult(ChartDataEntity); |
|
|
|
ChartDataEntity.setStartTime(DateUtils.stringToDate(weekStartdate)); |
|
|
|
Long weekCount = wxChartDataMapper.findSumResult(ChartDataEntity); |
|
|
|
Map<String, Long> map = new HashMap<>(); |
|
|
|
map.put("yesterdayCount", yesterdayCount); |
|
|
|
map.put("weekCount", weekCount); |
|
|
|
return new ResultData(map); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData queryMonthVos(EnumChartType chartType, TenantEntity tenantEntity) { |
|
|
|
Date now = new Date(); |
|
|
|
String monthStartdate = DateUtils.getTimeBefore(30, now); |
|
|
|
String yesyeweekDate = DateUtils.getTimeBefore(8, now);//计算周同比时间 |
|
|
|
String weekStartdate = DateUtils.getTimeBefore(7, now); |
|
|
|
String yesyesDate = DateUtils.getTimeBefore(2, now);//计算日同比时间 |
|
|
|
String yesterdayDate = DateUtils.getTimeBefore(1, now); |
|
|
|
List<String> tjTimeList = DateUtils.getTjTimeList(monthStartdate, yesterdayDate, "0"); |
|
|
|
|
|
|
|
WxChartDataEntity ChartDataEntity = new WxChartDataEntity(); |
|
|
|
ChartDataEntity.updateTenantInfo(tenantEntity); |
|
|
|
ChartDataEntity.setType(chartType.getCode()); |
|
|
|
ChartDataEntity.setStartTime(DateUtils.stringToDate(monthStartdate)); |
|
|
|
ChartDataEntity.setEndTime(DateUtils.stringToDate(yesterdayDate)); |
|
|
|
List<WxChartDataEntity> list = wxChartDataMapper.findList(ChartDataEntity); |
|
|
|
|
|
|
|
Map<String, String> collect = list.stream().collect(Collectors.toMap(m -> { |
|
|
|
return new SimpleDateFormat("yyyy-MM-dd").format(m.getQuerytime()); |
|
|
|
}, m -> { |
|
|
|
return m.getResult(); |
|
|
|
})); |
|
|
|
|
|
|
|
List<UserStructureVo> weekVos = new ArrayList<>(); |
|
|
|
List<UserStructureVo> monthVos = new ArrayList<>(); |
|
|
|
long yesterdayCount = 0l,yesyesCount = 0l,yesWeekCount = 0l; |
|
|
|
for (String date : tjTimeList) { |
|
|
|
UserStructureVo vo = new UserStructureVo(); |
|
|
|
vo.setName(date.substring(5).replace("-", "/")); |
|
|
|
String result = collect.get(date); |
|
|
|
if(StringUtils.isBlank(result)){ |
|
|
|
vo.setCount(0l); |
|
|
|
}else{ |
|
|
|
vo.setCount(Long.parseLong(result)); |
|
|
|
} |
|
|
|
if(weekStartdate.equals(date) || (DateUtils.stringToDate(weekStartdate).before(DateUtils.stringToDate(date)))){ |
|
|
|
weekVos.add(vo); |
|
|
|
} |
|
|
|
if(yesterdayDate.equals(date)){//昨日 |
|
|
|
yesterdayCount = vo.getCount(); |
|
|
|
} |
|
|
|
if(yesyesDate.equals(date)){//昨日的昨日(计算日环比) |
|
|
|
yesyesCount = vo.getCount(); |
|
|
|
} |
|
|
|
if(yesyeweekDate.equals(date)){//一周前的昨日(计算周同比) |
|
|
|
yesWeekCount = vo.getCount(); |
|
|
|
} |
|
|
|
monthVos.add(vo); |
|
|
|
} |
|
|
|
|
|
|
|
NumberFormat nf = NumberFormat.getPercentInstance(); |
|
|
|
nf.setMinimumFractionDigits(2); |
|
|
|
String dayPercentage = "--"; |
|
|
|
if (yesyesCount > 0) { |
|
|
|
Long count = yesterdayCount - yesyesCount; |
|
|
|
dayPercentage = nf.format(count.doubleValue() / new Double(yesyesCount).doubleValue()); |
|
|
|
} |
|
|
|
String weekPercentage = "--"; |
|
|
|
if (yesWeekCount > 0) { |
|
|
|
Long count = yesterdayCount - yesWeekCount; |
|
|
|
weekPercentage = nf.format(count.doubleValue() / new Double(yesWeekCount).doubleValue()); |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("weekVos", weekVos); |
|
|
|
map.put("monthVos", monthVos); |
|
|
|
map.put("dayPercentage", dayPercentage);//日环比 |
|
|
|
map.put("weekPercentage", weekPercentage);//周同比 |
|
|
|
return new ResultData(map); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMallService wxMallService; |
|
|
|
@Autowired |
|
|
|
@@ -93,8 +187,7 @@ public class WxChartServiceImpl implements WxChartDataService { |
|
|
|
WxBillOtherMapper wxBillOtherMapper; |
|
|
|
@Autowired |
|
|
|
WxBillAllMapper wxBillAllMapper; |
|
|
|
@Autowired |
|
|
|
WxChartDataMapper wxChartDataMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Lazy |
|
|
|
@Autowired |
|
|
|
@@ -132,7 +225,8 @@ public class WxChartServiceImpl implements WxChartDataService { |
|
|
|
@Autowired |
|
|
|
private WxShopService wxShopService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultData queryData(Map<String, String> paramsMap) { |
|
|
|
String tenantId = paramsMap.get("tenantId"); |
|
|
|
|