|
@@ -1,6 +1,7 @@
|
|
|
package com.goafanti.report.service;
|
|
package com.goafanti.report.service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -10,27 +11,38 @@ import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.commons.lang3.time.DateFormatUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.druid.sql.visitor.functions.If;
|
|
|
import com.goafanti.common.constant.AFTConstants;
|
|
import com.goafanti.common.constant.AFTConstants;
|
|
|
import com.goafanti.common.dao.DailySalesReportMapper;
|
|
import com.goafanti.common.dao.DailySalesReportMapper;
|
|
|
|
|
+import com.goafanti.common.dao.UserMapper;
|
|
|
import com.goafanti.common.error.BusinessException;
|
|
import com.goafanti.common.error.BusinessException;
|
|
|
import com.goafanti.common.model.DailySalesReport;
|
|
import com.goafanti.common.model.DailySalesReport;
|
|
|
import com.goafanti.core.mybatis.BaseMybatisDao;
|
|
import com.goafanti.core.mybatis.BaseMybatisDao;
|
|
|
|
|
+import com.goafanti.core.mybatis.page.Pagination;
|
|
|
|
|
+import com.goafanti.report.bo.CountDepMarketingStatisticsBo;
|
|
|
|
|
+import com.goafanti.report.bo.CountMarketingStatisticsBo;
|
|
|
import com.goafanti.report.bo.DepartmentSalesReportBO;
|
|
import com.goafanti.report.bo.DepartmentSalesReportBO;
|
|
|
import com.goafanti.report.bo.PersonalSalesReportBO;
|
|
import com.goafanti.report.bo.PersonalSalesReportBO;
|
|
|
import com.goafanti.report.bo.ReportDate;
|
|
import com.goafanti.report.bo.ReportDate;
|
|
|
import com.goafanti.report.bo.SalesValues;
|
|
import com.goafanti.report.bo.SalesValues;
|
|
|
|
|
+import com.goafanti.report.bo.SomeTimeMarketingBo;
|
|
|
|
|
+import com.goafanti.report.bo.marketingESBo;
|
|
|
import com.goafanti.report.enums.OrderBy;
|
|
import com.goafanti.report.enums.OrderBy;
|
|
|
import com.goafanti.report.enums.SalesReportOrderField;
|
|
import com.goafanti.report.enums.SalesReportOrderField;
|
|
|
|
|
+import com.goafanti.report.enums.TimeType;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMapper> {
|
|
public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMapper> {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
DailySalesReportMapper salesReportMapper;
|
|
DailySalesReportMapper salesReportMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ UserMapper userMapper;
|
|
|
|
|
|
|
|
public int insertDailyReports(Date startTime, Date endTime) {
|
|
public int insertDailyReports(Date startTime, Date endTime) {
|
|
|
List<DailySalesReport> list = salesReportMapper.selectAdmins();
|
|
List<DailySalesReport> list = salesReportMapper.selectAdmins();
|
|
@@ -243,4 +255,225 @@ public class SalesReportServiceImpl extends BaseMybatisDao<DailySalesReportMappe
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public List<marketingESBo> marketingStatistics(String depId) {
|
|
|
|
|
+ List<marketingESBo> list=salesReportMapper.findmarketingStatisticsList(depId);
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ for (marketingESBo m : list) {
|
|
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
|
|
+ marketingESBo day=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getDailyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getDailyEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> daily =valuesloading(day);
|
|
|
|
|
+ map.put("daily", daily);
|
|
|
|
|
+ marketingESBo weekly=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getWeeklyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getWeeklyEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> week =valuesloading(weekly);
|
|
|
|
|
+ map.put("week", week);
|
|
|
|
|
+ marketingESBo month=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getMonthStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getMonthEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> months =valuesloading(month);
|
|
|
|
|
+ map.put("months", months);
|
|
|
|
|
+ marketingESBo year=userMapper.marketingStatistics(m.getId(),DateFormatUtils.format(rd.getYearStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getYearEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> annual =valuesloading(year);
|
|
|
|
|
+ map.put("annual", annual);
|
|
|
|
|
+ m.setValues(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private Map<String, String> valuesloading(marketingESBo day) {
|
|
|
|
|
+ Map<String, String> map=new HashMap<>();
|
|
|
|
|
+ if (null!=day) {
|
|
|
|
|
+ map.put("VisitNo", day.getYearVisitNo());
|
|
|
|
|
+ map.put("TelNo", day.getYearTelNo());
|
|
|
|
|
+ map.put("FollowNo", day.getYearFollowNo());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ map.put("VisitNo", "0");
|
|
|
|
|
+ map.put("TelNo", "0");
|
|
|
|
|
+ map.put("FollowNo", "0");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<marketingESBo> marketingDepStatistics(String depId) {
|
|
|
|
|
+ List<marketingESBo> list=salesReportMapper.marketingDepStatisticsList(depId);
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ for (marketingESBo m : list) {
|
|
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
|
|
+ marketingESBo day=null;
|
|
|
|
|
+ if(null!=m.getDepartmentId())day=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getDailyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getDailyEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> daily =valuesloading(day);
|
|
|
|
|
+ if (null==day||null==day.getYearFollowNo()||null==m.getDepartmentNumber()) {
|
|
|
|
|
+ daily.put("AVG", "0");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ daily.put("AVG", calculateAVG(day.getYearFollowNo(),m.getDepartmentNumber()));
|
|
|
|
|
+ }
|
|
|
|
|
+ map.put("daily", daily);
|
|
|
|
|
+ marketingESBo weekly=null;
|
|
|
|
|
+ if(null!=m.getDepartmentId())weekly=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getWeeklyStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getWeeklyEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> week =valuesloading(weekly);
|
|
|
|
|
+ map.put("week", week);
|
|
|
|
|
+ marketingESBo month=null;
|
|
|
|
|
+ if(null!=m.getDepartmentId())month=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getMonthStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getMonthEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> months =valuesloading(month);
|
|
|
|
|
+ map.put("months", months);
|
|
|
|
|
+ marketingESBo year=null;
|
|
|
|
|
+ if(null!=m.getDepartmentId())year=userMapper.marketingDepStatistics(m.getDepartmentId(),DateFormatUtils.format(rd.getYearStart(), AFTConstants.YYYYMMDDHHMMSS),DateFormatUtils.format(rd.getYearEnd(), AFTConstants.YYYYMMDDHHMMSS));
|
|
|
|
|
+ Map<String,String> annual =valuesloading(year);
|
|
|
|
|
+ map.put("annual", annual);
|
|
|
|
|
+ m.setValues(map);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CountMarketingStatisticsBo countMarketingStatistics(String depId) {
|
|
|
|
|
+ CountMarketingStatisticsBo count=salesReportMapper.privateCustomersCount(depId);
|
|
|
|
|
+ if (null==count) {
|
|
|
|
|
+ count=new CountMarketingStatisticsBo();
|
|
|
|
|
+ }
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ CountMarketingStatisticsBo d=userMapper.countmarketingDepStatistics(depId,rd.getStringDailyStart(),rd.getStringDailyEnd());
|
|
|
|
|
+ if (null!=d.getYearFollowNo()) {
|
|
|
|
|
+ count.setDailyFollowNo(d.getYearFollowNo());
|
|
|
|
|
+ count.setDailyTelNo(d.getYearTelNo());
|
|
|
|
|
+ count.setDailyVisitNo(d.getYearVisitNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ CountMarketingStatisticsBo w=userMapper.countmarketingDepStatistics(depId,rd.getStringWeeklyStart(),rd.getStringWeeklyEnd());
|
|
|
|
|
+ if (null!=w) {
|
|
|
|
|
+ count.setWeeklyFollowNo(w.getYearFollowNo());
|
|
|
|
|
+ count.setWeeklyTelNo(w.getYearTelNo());
|
|
|
|
|
+ count.setWeeklyVisitNo(w.getYearVisitNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ CountMarketingStatisticsBo m=userMapper.countmarketingDepStatistics(depId,rd.getStringMonthStart(),rd.getStringMonthEnd());
|
|
|
|
|
+ if (null!=d) {
|
|
|
|
|
+ count.setMonthFollowNo(m.getYearFollowNo());
|
|
|
|
|
+ count.setMonthTelNo(m.getYearTelNo());
|
|
|
|
|
+ count.setMonthVisitNo(m.getYearVisitNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ CountMarketingStatisticsBo y=userMapper.countmarketingDepStatistics(depId,rd.getStringYearStart(),rd.getStringYearEnd());
|
|
|
|
|
+ if (null!=d) {
|
|
|
|
|
+ count.setYearFollowNo(y.getYearFollowNo());
|
|
|
|
|
+ count.setYearTelNo(y.getYearTelNo());
|
|
|
|
|
+ count.setYearVisitNo(y.getYearVisitNo());
|
|
|
|
|
+ }
|
|
|
|
|
+ return count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public CountMarketingStatisticsBo countMarketingDepStatistics(String depId) {
|
|
|
|
|
+
|
|
|
|
|
+ CountDepMarketingStatisticsBo count=salesReportMapper.privateCustomersDepCount(depId);
|
|
|
|
|
+ if (null==count) {
|
|
|
|
|
+ return new CountDepMarketingStatisticsBo();
|
|
|
|
|
+ }
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ CountMarketingStatisticsBo d=userMapper.countmarketingDepStatistics(depId,rd.getStringDailyStart(),rd.getStringDailyEnd());
|
|
|
|
|
+ if (null!=d) {
|
|
|
|
|
+ count.setDailyFollowNo(d.getYearFollowNo());
|
|
|
|
|
+ count.setDailyTelNo(d.getYearTelNo());
|
|
|
|
|
+ count.setDailyVisitNo(d.getYearVisitNo());
|
|
|
|
|
+ count.setDailyAVG(calculateAVG(count.getDailyFollowNo(),count.getDepartmentNumber()));
|
|
|
|
|
+ }
|
|
|
|
|
+ CountMarketingStatisticsBo w=userMapper.countmarketingDepStatistics(depId,rd.getStringWeeklyStart(),rd.getStringWeeklyEnd());
|
|
|
|
|
+ if (null!=w) {
|
|
|
|
|
+ count.setWeeklyFollowNo(w.getYearFollowNo());
|
|
|
|
|
+ count.setWeeklyTelNo(w.getYearTelNo());
|
|
|
|
|
+ count.setWeeklyVisitNo(w.getYearVisitNo());
|
|
|
|
|
+ count.setWeeklyAVG(calculateAVG(count.getWeeklyFollowNo(),count.getDepartmentNumber()));
|
|
|
|
|
+ }
|
|
|
|
|
+ CountMarketingStatisticsBo m=userMapper.countmarketingDepStatistics(depId,rd.getStringMonthStart(),rd.getStringMonthEnd());
|
|
|
|
|
+ if (null!=m) {
|
|
|
|
|
+ count.setMonthFollowNo(m.getYearFollowNo());
|
|
|
|
|
+ count.setMonthTelNo(m.getYearTelNo());
|
|
|
|
|
+ count.setMonthVisitNo(m.getYearVisitNo());
|
|
|
|
|
+ count.setMonthAVG(calculateAVG(count.getMonthFollowNo(),count.getDepartmentNumber()));
|
|
|
|
|
+ }
|
|
|
|
|
+ CountMarketingStatisticsBo y=userMapper.countmarketingDepStatistics(depId,rd.getStringYearStart(),rd.getStringYearEnd());
|
|
|
|
|
+ if (null!=y) {
|
|
|
|
|
+ count.setYearFollowNo(y.getYearFollowNo());
|
|
|
|
|
+ count.setYearTelNo(y.getYearTelNo());
|
|
|
|
|
+ count.setYearVisitNo(y.getYearVisitNo());
|
|
|
|
|
+ count.setYearAVG(calculateAVG(count.getYearFollowNo(),count.getDepartmentNumber()));
|
|
|
|
|
+ }
|
|
|
|
|
+ return count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public String calculateAVG(String a, String b) {
|
|
|
|
|
+ if (StringUtils.isNumeric(a)&&StringUtils.isNumeric(b)) {
|
|
|
|
|
+ if ((float)Integer.valueOf(a)==0||(float)Integer.valueOf(b)==0)return "0";
|
|
|
|
|
+ float f=(float)Integer.valueOf(a)/(float)Integer.valueOf(b);
|
|
|
|
|
+ return String.valueOf(f);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return"0";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SomeTimeMarketingBo> sometimeMarketingStatistics(String depId, Integer timeType, String startTime, String endTime) {
|
|
|
|
|
+ List<SomeTimeMarketingBo> list = null;
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ if (TimeType.WEEKLY.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingStatistics(depId,rd.getStringWeeklyStart(),rd.getStringWeeklyEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.MONTH.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingStatistics(depId,rd.getStringMonthStart(),rd.getStringMonthEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.QTR.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingStatistics(depId,rd.getStringQuarterStart(),rd.getStringQuarterEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.YEAR.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingStatistics(depId,rd.getStringYearStart(),rd.getStringYearEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.ZS.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingStatistics(depId,startTime,endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<SomeTimeMarketingBo> sometimeMarketingDepStatistics(String depId, Integer timeType, String startTime, String endTime) {
|
|
|
|
|
+ List<SomeTimeMarketingBo> list = null;
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ if (TimeType.WEEKLY.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingDepStatistics(depId,rd.getStringWeeklyStart(),rd.getStringWeeklyEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.MONTH.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingDepStatistics(depId,rd.getStringMonthStart(),rd.getStringMonthEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.QTR.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingDepStatistics(depId,rd.getStringQuarterStart(),rd.getStringQuarterEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.YEAR.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingDepStatistics(depId,rd.getStringYearStart(),rd.getStringYearEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.ZS.getCode()==timeType) {
|
|
|
|
|
+ list=salesReportMapper.sometimeMarketingDepStatistics(depId,startTime,endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public SomeTimeMarketingBo countSometimeMarketingStatistics(String depId, Integer timeType, String startTime, String endTime) {
|
|
|
|
|
+ ReportDate rd = new ReportDate(new Date());
|
|
|
|
|
+ if (TimeType.WEEKLY.getCode()==timeType) {
|
|
|
|
|
+ return salesReportMapper.countsometimeMarketingStatistics(depId,rd.getStringWeeklyStart(),rd.getStringWeeklyEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.MONTH.getCode()==timeType) {
|
|
|
|
|
+ return salesReportMapper.countsometimeMarketingStatistics(depId,rd.getStringMonthStart(),rd.getStringMonthEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.QTR.getCode()==timeType) {
|
|
|
|
|
+ return salesReportMapper.countsometimeMarketingStatistics(depId,rd.getStringQuarterStart(),rd.getStringQuarterEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.YEAR.getCode()==timeType) {
|
|
|
|
|
+ return salesReportMapper.countsometimeMarketingStatistics(depId,rd.getStringYearStart(),rd.getStringYearEnd());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (TimeType.ZS.getCode()==timeType) {
|
|
|
|
|
+ return salesReportMapper.countsometimeMarketingStatistics(depId,startTime,endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public SomeTimeMarketingBo countSometimeMarketingDepStatistics(String depId, Integer timeType, String startTime,
|
|
|
|
|
+ String endTime) {
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|