|
@@ -206,116 +206,142 @@ public class ReportServiceImpl implements ReportService {
|
|
|
|
|
|
@Override
|
|
|
public PackageCodeTypeRes queryPackageCodeGeneral(ReportReq reportReq) {
|
|
|
- PackageCodeTypeRes res = new PackageCodeTypeRes();
|
|
|
- int before=0;//往期
|
|
|
- int present=0;//同期
|
|
|
- //封装入参
|
|
|
- Map<String,LocalDateTime> map=null;
|
|
|
- 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"));
|
|
|
- if(1==reportReq.getValue()){//周
|
|
|
- map=getBeforeWeekTimes();
|
|
|
- }
|
|
|
- if(2==reportReq.getValue()){//月
|
|
|
- map=getBeforeMonthTime();
|
|
|
- }
|
|
|
+ Map<String,LocalDateTime> map=new HashMap<String,LocalDateTime>();
|
|
|
+ //判断是否有参数值
|
|
|
+ if(null!= reportReq.getValue()){
|
|
|
+ map= FillParam(reportReq,map);
|
|
|
}
|
|
|
+ PackageCodeTypeRes res = new PackageCodeTypeRes();
|
|
|
+
|
|
|
//1.生成码数量
|
|
|
- getGenerateCodeNum(reportReq, res,present,before,map);
|
|
|
+ getGenerateCodeNum(reportReq,res,map);
|
|
|
//2.下载码数量
|
|
|
- getLoadCodeNum(reportReq, res,present,before,map);
|
|
|
+ getLoadCodeNum(reportReq, res,map);
|
|
|
//3.激活码数量
|
|
|
- getActivateCodeNum(reportReq, res,present,before,map);
|
|
|
+ getActivateCodeNum(reportReq, res,map);
|
|
|
//返回参数
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- private void getGenerateCodeNum(ReportReq reportReq, PackageCodeTypeRes res, int present, int before,Map<String,LocalDateTime> map) {
|
|
|
- List<ListPackageCodeVo> createList = reportServiceMapper.queryPackageCodeNum(reportReq,map.get("beginDate"), map.get("endDate"));
|
|
|
- /**
|
|
|
- * 处理逻辑
|
|
|
- * 1.取出本周的数据集
|
|
|
- * 2.取出不是本周的数据集
|
|
|
- * 3.本周的数据集-不是本周的数据集/不是本周的数据集*100%
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * 封装入参
|
|
|
+ * @param reportReq
|
|
|
+ * @param map
|
|
|
+ */
|
|
|
+ private Map FillParam(ReportReq reportReq,Map<String,LocalDateTime> map) {
|
|
|
+ if(null != reportReq.getValue() && null == reportReq.getEndTime() && null == reportReq.getBeginTime()){
|
|
|
+ setQueryTime(reportReq);
|
|
|
+ reportReq.setBeginTime(reportReq.getBeginTime());
|
|
|
+ reportReq.setEndTime(reportReq.getEndTime());
|
|
|
+ }
|
|
|
+ if("1".equals(reportReq.getValue().toString())){//周
|
|
|
+ map=getBeforeWeekTimes();
|
|
|
+ }
|
|
|
+ if("2".equals(reportReq.getValue().toString())){//月
|
|
|
+ map=getBeforeMonthTime();
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 处理逻辑
|
|
|
+ * 1.取出当前的数据集,对箱码,盖码赋值
|
|
|
+ * 2.获取往期总数
|
|
|
+ * 3.(本周的数据集-不是本周的数据集)/不是本周的数据集*100%,计算同比增长率
|
|
|
+ */
|
|
|
+ private void getGenerateCodeNum(ReportReq reportReq, PackageCodeTypeRes res,Map<String,LocalDateTime> map) {
|
|
|
+ List<ListPackageCodeVo> createList = reportServiceMapper.queryPackageCodeNum(reportReq);
|
|
|
+ ListPackageCodeVo vo=null;
|
|
|
+ if(!map.isEmpty()){
|
|
|
+ vo=reportServiceMapper.queryPackageCodeNumPast(map.get("beginDate"),map.get("endDate"));
|
|
|
+ }
|
|
|
for (int i = 0; i < createList.size(); i++) {
|
|
|
- if("0".equals(createList.get(i).getPercent())){
|
|
|
- if (QrTypeEnum.CARTON.getCode().equals(createList.get(i).getQrType())) {//判断是否箱码
|
|
|
- res.setCreateBoxNumber(createList.get(i).getQrNumber());//箱码
|
|
|
- } else if (QrTypeEnum.CAP.getCode().equals(createList.get(i).getQrType())) {//判断是否盖码
|
|
|
- res.setCreateCapNumber(createList.get(i).getQrNumber());//盖码
|
|
|
- }
|
|
|
+ if (QrTypeEnum.CARTON.getCode().equals(createList.get(i).getQrType())) {//判断是否箱码
|
|
|
+ res.setCreateBoxNumber(createList.get(i).getQrNumber());//箱码
|
|
|
+ } else if (QrTypeEnum.CAP.getCode().equals(createList.get(i).getQrType())) {//判断是否盖码
|
|
|
+ res.setCreateCapNumber(createList.get(i).getQrNumber());//盖码
|
|
|
}
|
|
|
}
|
|
|
- if (StringUtils.isNotEmpty(reportReq.getValue() + "")) {
|
|
|
- //计算同期和往期的箱码和盖码
|
|
|
- String vaiue=reportReq.getValue() + "";
|
|
|
- before = createList.stream().filter(x -> x.getPercent().equals(vaiue)).mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
- present = createList.stream().filter(x -> x.getPercent().equals("0")).mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
- BigDecimal number = new BigDecimal(0);
|
|
|
- BigDecimal preNum = BigDecimal.valueOf((int) present);
|
|
|
- BigDecimal sufNum = BigDecimal.valueOf((int) before);
|
|
|
- String result = percentBigDecimal(preNum, sufNum);
|
|
|
- res.setCreatePercent(result);//获取同比增长率
|
|
|
+ if (null !=reportReq.getValue()) {
|
|
|
+ //获取往期总数
|
|
|
+ long before=0;
|
|
|
+ if(!ObjectUtils.isEmpty(vo)){
|
|
|
+ before = vo.getQrNumber();
|
|
|
+ }else{
|
|
|
+ before=0;
|
|
|
+ }
|
|
|
+ //计算同期总数
|
|
|
+ int present = createList.stream().mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
+ //获取同比增长率
|
|
|
+ String result = percentBigDecimal(present, before);
|
|
|
+ res.setCreatePercent(result);
|
|
|
}
|
|
|
}
|
|
|
- private void getLoadCodeNum(ReportReq reportReq, PackageCodeTypeRes res, int present, int before,Map<String,LocalDateTime> map) {
|
|
|
- List<ListPackageCodeVo> loadList = reportServiceMapper.queryLoadPackageCodeNum(reportReq,map.get("beginDate"), map.get("endDate"));
|
|
|
+ private void getLoadCodeNum(ReportReq reportReq, PackageCodeTypeRes res,Map<String,LocalDateTime> map) {
|
|
|
+ List<ListPackageCodeVo> loadList = reportServiceMapper.queryLoadPackageCodeNum(reportReq);
|
|
|
+ ListPackageCodeVo vo = null;
|
|
|
+ if(!map.isEmpty()){
|
|
|
+ vo=reportServiceMapper.queryLoadPackageCodeNumPast(map.get("beginDate"),map.get("endDate"));
|
|
|
+ }
|
|
|
for (int i = 0; i < loadList.size(); i++) {
|
|
|
- if("0".equals(loadList.get(i).getPercent())) {
|
|
|
- if (QrTypeEnum.CARTON.getCode().equals(loadList.get(i).getQrType())) {
|
|
|
- res.setLoadBoxNumber(loadList.get(i).getQrNumber());
|
|
|
- } else if (QrTypeEnum.CAP.getCode().equals(loadList.get(i).getQrType())) {
|
|
|
- res.setLoadCapNumber(loadList.get(i).getQrNumber());
|
|
|
- }
|
|
|
+ if (QrTypeEnum.CARTON.getCode().equals(loadList.get(i).getQrType())) {
|
|
|
+ res.setLoadBoxNumber(loadList.get(i).getQrNumber());
|
|
|
+ } else if (QrTypeEnum.CAP.getCode().equals(loadList.get(i).getQrType())) {
|
|
|
+ res.setLoadCapNumber(loadList.get(i).getQrNumber());
|
|
|
}
|
|
|
}
|
|
|
- if (StringUtils.isNotEmpty(reportReq.getValue() + "")) {
|
|
|
- //计算同期和往期的箱码和盖码
|
|
|
- before = loadList.stream().filter(x -> x.getPercent().equals(reportReq.getValue())).mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
- //获取为0的
|
|
|
- present = loadList.stream().filter(x -> x.getPercent().equals("0")).mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
- BigDecimal number = new BigDecimal(0);
|
|
|
- BigDecimal preNum = BigDecimal.valueOf((int) present);
|
|
|
- BigDecimal sufNum = BigDecimal.valueOf((int) before);
|
|
|
- String result = percentBigDecimal(preNum, sufNum);
|
|
|
- res.setLoadPercent(result);//获取同比增长率
|
|
|
+ if (!ObjectUtils.isEmpty(reportReq) && null !=reportReq.getValue()) {
|
|
|
+ //获取往期总数
|
|
|
+ long before=0;
|
|
|
+ if(!ObjectUtils.isEmpty(vo)){
|
|
|
+ before = vo.getQrNumber();
|
|
|
+ }else{
|
|
|
+ before=0;
|
|
|
+ }
|
|
|
+ //获取同期总数
|
|
|
+ int present = loadList.stream().mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
+ //获取同比增长率
|
|
|
+ String result = percentBigDecimal(present, before);
|
|
|
+ res.setLoadPercent(result);
|
|
|
}
|
|
|
}
|
|
|
- private void getActivateCodeNum(ReportReq reportReq, PackageCodeTypeRes res, int present, int before,Map<String,LocalDateTime> map) {
|
|
|
- List<ListPackageCodeVo> activateList = reportServiceMapper.queryActivateCodeNum(reportReq,map.get("beginDate"), map.get("endDate"));
|
|
|
+ private void getActivateCodeNum(ReportReq reportReq, PackageCodeTypeRes res,Map<String,LocalDateTime> map) {
|
|
|
+ List<ListPackageCodeVo> activateList = reportServiceMapper.queryActivateCodeNum(reportReq);
|
|
|
+ ListPackageCodeVo vo=null;
|
|
|
+ if(!map.isEmpty()){
|
|
|
+ vo=reportServiceMapper.queryActivateCodeNumPast(map.get("beginDate"),map.get("endDate"));
|
|
|
+ }
|
|
|
for (int i = 0; i < activateList.size(); i++) {
|
|
|
- if("0".equals(activateList.get(i).getPercent())) {
|
|
|
if (QrTypeEnum.CARTON.getCode().equals(activateList.get(i).getQrType())) {
|
|
|
res.setActivateBoxNumber(activateList.get(i).getQrNumber());
|
|
|
} else if (QrTypeEnum.CAP.getCode().equals(activateList.get(i).getQrType())) {
|
|
|
res.setActivateCapNumber(activateList.get(i).getQrNumber());
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
- if (StringUtils.isNotEmpty(reportReq.getValue() + "")) {
|
|
|
- //计算同期和往期的箱码和盖码
|
|
|
- before = activateList.stream().filter(x -> x.getPercent().equals(reportReq.getValue())).mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
- present = activateList.stream().filter(x -> x.getPercent().equals("0")).mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
- BigDecimal number = new BigDecimal(0);
|
|
|
- BigDecimal preNum = BigDecimal.valueOf((int) present);
|
|
|
- BigDecimal sufNum = BigDecimal.valueOf((int) before);
|
|
|
- String result = percentBigDecimal(preNum, sufNum);
|
|
|
- res.setActivatePercent(result);//获取同比增长率
|
|
|
+ if (!ObjectUtils.isEmpty(reportReq) && null !=reportReq.getValue()) {
|
|
|
+ //获取往期总数
|
|
|
+ long before=0;
|
|
|
+ if(!ObjectUtils.isEmpty(vo)){
|
|
|
+ before = vo.getQrNumber();
|
|
|
+ }else{
|
|
|
+ before=0;
|
|
|
+ }
|
|
|
+ //获取同期码总数
|
|
|
+ int present = activateList.stream().mapToInt(x -> Math.toIntExact(x.getQrNumber())).sum();
|
|
|
+ //获取同比增长率
|
|
|
+ String result = percentBigDecimal(present, before);
|
|
|
+ res.setActivatePercent(result);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
/**
|
|
|
- * @param preNum 同期数
|
|
|
- * @param sufNum 往期数
|
|
|
+ * @param present 同期数
|
|
|
+ * @param before 往期数
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String percentBigDecimal(BigDecimal preNum, BigDecimal sufNum) {
|
|
|
+ public static String percentBigDecimal(int present, long before) {
|
|
|
+ BigDecimal preNum = BigDecimal.valueOf(present);
|
|
|
+ BigDecimal sufNum = BigDecimal.valueOf(before);
|
|
|
double result = countDecimal(preNum, sufNum);
|
|
|
if (result > 0) {
|
|
|
- System.out.println("上升" + result + "%");
|
|
|
return "+" + result + "%";
|
|
|
}
|
|
|
if (result < 0) {
|
|
@@ -378,7 +404,6 @@ public class ReportServiceImpl implements ReportService {
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 获取上月月初和月末日期
|
|
|
* @return
|
|
@@ -389,13 +414,10 @@ public class ReportServiceImpl implements ReportService {
|
|
|
String localTime = fmt.format(LocalDateTime.now());
|
|
|
LocalDateTime date2 = LocalDateTime.parse(localTime, fmt);
|
|
|
LocalDateTime localDateTime = date2.minusMonths(1);
|
|
|
- LocalDateTime with = localDateTime.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
- LocalDateTime with2 = localDateTime.with(TemporalAdjusters.firstDayOfMonth());
|
|
|
- map.put("beginDate",localDateTime.with(TemporalAdjusters.lastDayOfMonth()));
|
|
|
- map.put("endDate",localDateTime.with(TemporalAdjusters.firstDayOfMonth()));
|
|
|
+ map.put("beginDate",localDateTime.with(TemporalAdjusters.firstDayOfMonth()));
|
|
|
+ map.put("endDate",localDateTime.with(TemporalAdjusters.lastDayOfMonth()));
|
|
|
return map;
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 获取上周周一和周末的数据
|
|
|
* @return
|