|
@@ -1,13 +1,17 @@
|
|
package com.ygj.yuemum.service.promotion;
|
|
package com.ygj.yuemum.service.promotion;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.ygj.yuemum.dao.promotion.PromotionChannelLogDao;
|
|
import com.ygj.yuemum.dao.promotion.PromotionChannelLogDao;
|
|
|
|
+import com.ygj.yuemum.domain.promotion.PromotionChannel;
|
|
import com.ygj.yuemum.domain.promotion.PromotionChannelLog;
|
|
import com.ygj.yuemum.domain.promotion.PromotionChannelLog;
|
|
|
|
+import com.ygj.yuemum.domain.promotion.PromotionChannelLogDate;
|
|
|
|
+import com.ygj.yuemum.domain.promotion.PromotionChannelQuery;
|
|
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 java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class PromotionChannelLogService {
|
|
public class PromotionChannelLogService {
|
|
@@ -25,4 +29,83 @@ public class PromotionChannelLogService {
|
|
return promotionChannelLogDao.insertPromotionChannelLog(promotionChannelLog);
|
|
return promotionChannelLogDao.insertPromotionChannelLog(promotionChannelLog);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public List<PromotionChannelLog> groupPromotionChannelLogs(PromotionChannelQuery promotionChannelQuery){
|
|
|
|
+ return promotionChannelLogDao.groupPromotionChannelLogs(promotionChannelQuery);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getPClCharts(PromotionChannelQuery promotionChannelQuery) throws ParseException {
|
|
|
|
+ //先查结果集 日期 渠道
|
|
|
|
+ //循环取出数据 根据上面所查询的日期和渠道
|
|
|
|
+ PromotionChannelLog promotionChannelQ = new PromotionChannelLog();
|
|
|
|
+ promotionChannelQ.setPcl_channel_code(promotionChannelQuery.getPcl_channel_code());
|
|
|
|
+ promotionChannelQ.setPrx_id(promotionChannelQuery.getPrx_id());
|
|
|
|
+ List<PromotionChannelLog> promotionChannels = promotionChannelLogDao.getPromotionChannelCharts(promotionChannelQ);
|
|
|
|
+ if (promotionChannels.size() > 0 ) {
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ List<String> dataDays = new ArrayList<>();
|
|
|
|
+ if (promotionChannelQuery.getPcl_startdate() != null && promotionChannelQuery.getPcl_enddate() != null){
|
|
|
|
+ if(promotionChannelQuery.getPcl_startdate().equals(promotionChannelQuery.getPcl_enddate())) {
|
|
|
|
+ dataDays.add(simpleDateFormat.format(simpleDateFormat.parse(promotionChannelQuery.getPcl_startdate())));
|
|
|
|
+ } else {
|
|
|
|
+ List<Date> listDate = getDatesBetweenTwoDate(simpleDateFormat.parse(promotionChannelQuery.getPcl_startdate()), simpleDateFormat.parse(promotionChannelQuery.getPcl_enddate()));
|
|
|
|
+ for(int i=0;i<listDate.size();i++){
|
|
|
|
+ dataDays.add(simpleDateFormat.format(listDate.get(i)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ //查询全部日期
|
|
|
|
+ PromotionChannelLogDate promotionChannelLogDate = promotionChannelLogDao.getPCLChartDate();
|
|
|
|
+ List<Date> listDate = getDatesBetweenTwoDate(simpleDateFormat.parse(promotionChannelLogDate.getPcl_date_min()), simpleDateFormat.parse(promotionChannelLogDate.getPcl_date_max()));
|
|
|
|
+ for(int i=0;i<listDate.size();i++){
|
|
|
|
+ dataDays.add(simpleDateFormat.format(listDate.get(i)));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<String> dataChannel = new ArrayList<>();
|
|
|
|
+ LinkedHashMap<String, Object> tableData = new LinkedHashMap<>();
|
|
|
|
+ for (PromotionChannelLog promotionChannelLogs:promotionChannels){
|
|
|
|
+ dataChannel.add(promotionChannelLogs.getPcl_channel_name());
|
|
|
|
+ List<Integer> dataResult = new ArrayList<>();
|
|
|
|
+ for (int i=0; i<dataDays.size(); i++) {
|
|
|
|
+ PromotionChannelLog promotionChannelLog = new PromotionChannelLog();
|
|
|
|
+ promotionChannelLog.setPcl_channel_code(promotionChannelLogs.getPcl_channel_code());
|
|
|
|
+ promotionChannelLog.setPcl_date(dataDays.get(i));
|
|
|
|
+ int result = promotionChannelLogDao.getPCLChartCount(promotionChannelLog);
|
|
|
|
+ dataResult.add(result);
|
|
|
|
+ }
|
|
|
|
+ tableData.put(promotionChannelLogs.getPcl_channel_code(),dataResult);
|
|
|
|
+ }
|
|
|
|
+ Map tempMap = new HashMap<>();
|
|
|
|
+ tempMap.put("lineData",tableData);
|
|
|
|
+ tempMap.put("dataDays",dataDays);
|
|
|
|
+ tempMap.put("dataChannel",dataChannel);
|
|
|
|
+ Map returnMap = new HashMap<>();
|
|
|
|
+ returnMap.put("lineChartData",tempMap);
|
|
|
|
+ return JSONObject.toJSONString(returnMap);
|
|
|
|
+ } else {
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ public static List<Date> getDatesBetweenTwoDate(Date beginDate, Date endDate) {
|
|
|
|
+ List<Date> lDate = new ArrayList<Date>();
|
|
|
|
+ lDate.add(beginDate);// 把开始时间加入集合
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ // 使用给定的 Date 设置此 Calendar 的时间
|
|
|
|
+ cal.setTime(beginDate);
|
|
|
|
+ boolean bContinue = true;
|
|
|
|
+ while (bContinue) {
|
|
|
|
+ // 根据日历的规则,为给定的日历字段添加或减去指定的时间量
|
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
+ // 测试此日期是否在指定日期之后
|
|
|
|
+ if (endDate.after(cal.getTime())) {
|
|
|
|
+ lDate.add(cal.getTime());
|
|
|
|
+ } else {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ lDate.add(endDate);// 把结束时间加入集合
|
|
|
|
+ return lDate;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|