|
@@ -11,8 +11,15 @@ import com.abi.task.common.utils.PojoConverterUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -35,11 +42,18 @@ public class ReportServiceImpl implements ReportService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ListBrandCodeReportRes queryBrandCodeProportion(ReportReq reportReq) {
|
|
|
+ if(!ObjectUtils.isEmpty(reportReq) &&
|
|
|
+ null == reportReq.getEndTime() &&
|
|
|
+ null == reportReq.getBeginTime()){
|
|
|
+ HashMap<String, LocalDateTime> timestamp = getTimestamp(reportReq.getValue());
|
|
|
+ reportReq.setBeginTime( timestamp.get("startTime"));
|
|
|
+ reportReq.setEndTime( timestamp.get("endTime"));
|
|
|
+ }
|
|
|
//查询 品牌数量
|
|
|
List<ListBrandCodeReportVO> listReportVOS = reportServiceMapper.queryBrandCodeProportion(reportReq);
|
|
|
- //求总和
|
|
|
- Long collect = listReportVOS.stream().collect(Collectors.summingLong(ListBrandCodeReportVO::getQrNumber));
|
|
|
if(!CollectionUtils.isEmpty(listReportVOS)){
|
|
|
+ //求总和
|
|
|
+ Long collect = listReportVOS.stream().collect(Collectors.summingLong(ListBrandCodeReportVO::getQrNumber));
|
|
|
listReportVOS.forEach(listReportVO->{
|
|
|
long l = listReportVO.getQrNumber() / collect * 100;
|
|
|
listReportVO.setPercent(new DecimalFormat("#0.00").format(l + 0.000001d)+"%");
|
|
@@ -66,4 +80,76 @@ public class ReportServiceImpl implements ReportService {
|
|
|
res.setReportSkuCodeRankingResList(skuCodeReportResBeans);
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据类型获取时间范围
|
|
|
+ * @param timeType (0-当天,1-本周,2-本月)
|
|
|
+ * @return key 开始时间:startTime 结束时间:endTime
|
|
|
+ */
|
|
|
+ private static HashMap<String, LocalDateTime> getTimestamp(Integer timeType) {
|
|
|
+ HashMap<String, LocalDateTime> hashMap = new HashMap<String, LocalDateTime>();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+
|
|
|
+ //当天
|
|
|
+ if (timeType == 0){
|
|
|
+ hashMap.put("startTime", longTurnData(getTimestampByOffsetDay(0)));
|
|
|
+ hashMap.put("endTime", longTurnData(getTimestampByOffsetDay(1)));
|
|
|
+ }
|
|
|
+ //本周
|
|
|
+ if (timeType == 1){
|
|
|
+ hashMap.put(
|
|
|
+ "startTime",
|
|
|
+ longTurnData(getTimestampByOffsetDay(0 - calendar.get(Calendar.DAY_OF_WEEK) + 2)) );
|
|
|
+ hashMap.put(
|
|
|
+ "endTime",
|
|
|
+ longTurnData( getTimestampByOffsetDay(calendar
|
|
|
+ .getMaximum(Calendar.DAY_OF_WEEK)
|
|
|
+ - calendar.get(Calendar.DAY_OF_WEEK) + 1)));
|
|
|
+ }
|
|
|
+
|
|
|
+ //本月
|
|
|
+ if (timeType == 2){
|
|
|
+ hashMap.put(
|
|
|
+ "startTime",
|
|
|
+ longTurnData(getTimestampByOffsetDay(0 - calendar.get(Calendar.DAY_OF_MONTH) + 1)));
|
|
|
+ hashMap.put(
|
|
|
+ "endTime",
|
|
|
+ longTurnData( getTimestampByOffsetDay(calendar
|
|
|
+ .getMaximum(Calendar.DAY_OF_MONTH)
|
|
|
+ - calendar.get(Calendar.DAY_OF_MONTH))));
|
|
|
+ }
|
|
|
+ return hashMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间格式转化
|
|
|
+ * @author ludashi
|
|
|
+ * @date 2021/6/3 13:37
|
|
|
+ * @param l 时间毫秒值
|
|
|
+ * @return java.time.LocalDateTime
|
|
|
+ */
|
|
|
+ private static LocalDateTime longTurnData(Long l) {
|
|
|
+ Instant instant = Instant.ofEpochMilli(l);
|
|
|
+ ZoneId zone = ZoneId.systemDefault();
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
|
|
|
+ return localDateTime;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 时间定义
|
|
|
+ * @author ludashi
|
|
|
+ * @date 2021/6/3 13:12
|
|
|
+ * @param day
|
|
|
+ * @return long
|
|
|
+ */
|
|
|
+ public static long getTimestampByOffsetDay(int day){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, day);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ return calendar.getTimeInMillis();
|
|
|
+ }
|
|
|
+
|
|
|
}
|