Bläddra i källkod

Echarts报表开发

huan.wang 6 år sedan
förälder
incheckning
a6dfa4e2a9

+ 3 - 2
src/main/java/com/ygj/yuemum/controller/promotion/PromotionChannelController.java

@@ -2,10 +2,10 @@ package com.ygj.yuemum.controller.promotion;
 
 
 import com.ygj.yuemum.domain.promotion.PromotionChannel;
+import com.ygj.yuemum.domain.promotion.PromotionChannelQuery;
 import com.ygj.yuemum.service.promotion.PromotionChannelService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -19,4 +19,5 @@ public class PromotionChannelController {
     public List<PromotionChannel> getPromotionChannel(){
         return promotionChannelService.getPromotionChannel();
     }
+
 }

+ 13 - 0
src/main/java/com/ygj/yuemum/controller/promotion/PromotionChannelLogController.java

@@ -2,6 +2,7 @@ package com.ygj.yuemum.controller.promotion;
 
 
 import com.ygj.yuemum.domain.promotion.PromotionChannelLog;
+import com.ygj.yuemum.domain.promotion.PromotionChannelQuery;
 import com.ygj.yuemum.service.promotion.PromotionChannelLogService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.text.ParseException;
 import java.util.List;
 
 @RestController
@@ -26,4 +28,15 @@ public class PromotionChannelLogController {
     public int insertPromotionChannelLog(@ModelAttribute PromotionChannelLog promotionChannelLog) {
         return promotionChannelLogService.insertPromotionChannelLog(promotionChannelLog);
     }
+
+    @PostMapping("/groupPromotionChannelLogs")
+    public List<PromotionChannelLog> groupPromotionChannelLogs(@ModelAttribute PromotionChannelQuery promotionChannelQuery) {
+        return promotionChannelLogService.groupPromotionChannelLogs(promotionChannelQuery);
+    }
+
+    @PostMapping("/getPClCharts")
+    public String getPClCharts(@ModelAttribute PromotionChannelQuery promotionChannelQuery) throws ParseException {
+        return promotionChannelLogService.getPClCharts(promotionChannelQuery);
+    }
+
 }

+ 6 - 0
src/main/java/com/ygj/yuemum/dao/promotion/PromotionChannelLogDao.java

@@ -1,6 +1,8 @@
 package com.ygj.yuemum.dao.promotion;
 
 import com.ygj.yuemum.domain.promotion.PromotionChannelLog;
+import com.ygj.yuemum.domain.promotion.PromotionChannelLogDate;
+import com.ygj.yuemum.domain.promotion.PromotionChannelQuery;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -10,4 +12,8 @@ public interface PromotionChannelLogDao {
 
     List<PromotionChannelLog> getPromotionChannelLog();
     int insertPromotionChannelLog(PromotionChannelLog promotionChannelLog);
+    List<PromotionChannelLog> groupPromotionChannelLogs(PromotionChannelQuery promotionChannelQuery);
+    PromotionChannelLogDate getPCLChartDate();
+    int getPCLChartCount(PromotionChannelLog promotionChannelLog);
+    List <PromotionChannelLog> getPromotionChannelCharts(PromotionChannelLog promotionChannelLog);
 }

+ 9 - 0
src/main/java/com/ygj/yuemum/domain/promotion/PromotionChannel.java

@@ -3,6 +3,15 @@ package com.ygj.yuemum.domain.promotion;
 public class PromotionChannel {
     private Integer id;
     private String pc_name;
+    private String pc_code;
+
+    public String getPc_code() {
+        return pc_code;
+    }
+
+    public void setPc_code(String pc_code) {
+        this.pc_code = pc_code;
+    }
 
     public Integer getId() {
         return id;

+ 18 - 0
src/main/java/com/ygj/yuemum/domain/promotion/PromotionChannelLog.java

@@ -6,6 +6,24 @@ public class PromotionChannelLog {
     private String pcl_date;
     private String pcl_openid;
     private String pcl_channel_code;
+    private String pcl_channel_name;
+    private  Integer pcl_channel_group;
+
+    public Integer getPcl_channel_group() {
+        return pcl_channel_group;
+    }
+
+    public void setPcl_channel_group(Integer pcl_channel_group) {
+        this.pcl_channel_group = pcl_channel_group;
+    }
+
+    public String getPcl_channel_name() {
+        return pcl_channel_name;
+    }
+
+    public void setPcl_channel_name(String pcl_channel_name) {
+        this.pcl_channel_name = pcl_channel_name;
+    }
 
     public String getPcl_channel_code() {
         return pcl_channel_code;

+ 22 - 0
src/main/java/com/ygj/yuemum/domain/promotion/PromotionChannelLogDate.java

@@ -0,0 +1,22 @@
+package com.ygj.yuemum.domain.promotion;
+
+public class PromotionChannelLogDate {
+    private String pcl_date_max;
+    private String pcl_date_min;
+
+    public String getPcl_date_max() {
+        return pcl_date_max;
+    }
+
+    public void setPcl_date_max(String pcl_date_max) {
+        this.pcl_date_max = pcl_date_max;
+    }
+
+    public String getPcl_date_min() {
+        return pcl_date_min;
+    }
+
+    public void setPcl_date_min(String pcl_date_min) {
+        this.pcl_date_min = pcl_date_min;
+    }
+}

+ 40 - 0
src/main/java/com/ygj/yuemum/domain/promotion/PromotionChannelQuery.java

@@ -0,0 +1,40 @@
+package com.ygj.yuemum.domain.promotion;
+
+public class PromotionChannelQuery {
+    private Integer prx_id;
+    private String pcl_startdate;
+    private String pcl_enddate;
+    private String pcl_channel_code;
+
+    public Integer getPrx_id() {
+        return prx_id;
+    }
+
+    public void setPrx_id(Integer prx_id) {
+        this.prx_id = prx_id;
+    }
+
+    public String getPcl_startdate() {
+        return pcl_startdate;
+    }
+
+    public void setPcl_startdate(String pcl_startdate) {
+        this.pcl_startdate = pcl_startdate;
+    }
+
+    public String getPcl_enddate() {
+        return pcl_enddate;
+    }
+
+    public void setPcl_enddate(String pcl_enddate) {
+        this.pcl_enddate = pcl_enddate;
+    }
+
+    public String getPcl_channel_code() {
+        return pcl_channel_code;
+    }
+
+    public void setPcl_channel_code(String pcl_channel_code) {
+        this.pcl_channel_code = pcl_channel_code;
+    }
+}

+ 85 - 2
src/main/java/com/ygj/yuemum/service/promotion/PromotionChannelLogService.java

@@ -1,13 +1,17 @@
 package com.ygj.yuemum.service.promotion;
 
+import com.alibaba.fastjson.JSONObject;
 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.PromotionChannelLogDate;
+import com.ygj.yuemum.domain.promotion.PromotionChannelQuery;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class PromotionChannelLogService {
@@ -25,4 +29,83 @@ public class PromotionChannelLogService {
         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;
+    }
+
 }

+ 3 - 3
src/main/resources/application.yml

@@ -25,9 +25,9 @@ pagehelper:
   reasonable: true
   support-methods-arguments: true
   params: count=countSql
-#logging:
-#  level:
-#     com.ygj.yuemum.dao : debug
+logging:
+  level:
+     com.ygj.yuemum.dao : debug
 #优惠券批次号信息--------------------
 #测试
 coupon:

+ 66 - 0
src/main/resources/mybatis/mapper/promotion/PromotionChannelLogMapper.xml

@@ -17,6 +17,27 @@
         from promotion_channel_log
         order by 1 desc
     </select>
+    <select id="groupPromotionChannelLogs" resultType="com.ygj.yuemum.domain.promotion.PromotionChannelLog" parameterType="com.ygj.yuemum.domain.promotion.PromotionChannelQuery" >
+        SELECT
+            fgetPChannelname(pcl_channel_code) pcl_channel_name,
+            pcl_channel_code,
+            count(1) pcl_channel_group
+        FROM
+            promotion_channel_log
+        WHERE
+            1 = 1
+            <if test="prx_id != null and prx_id != ''">
+                and prx_id = #{prx_id,jdbcType=INTEGER}
+            </if>
+            <if test="pcl_channel_code != null and pcl_channel_code != ''">
+                and pcl_channel_code = #{pcl_channel_code,jdbcType=VARCHAR}
+            </if>
+        GROUP BY
+            pcl_channel_code
+        ORDER BY
+            pcl_channel_code ASC
+    </select>
+
     <insert id="insertPromotionChannelLog" parameterType="com.ygj.yuemum.domain.promotion.PromotionChannelLog" >
         insert into promotion_channel_log
         <trim prefix="(" suffix=")" suffixOverrides="," >
@@ -48,4 +69,49 @@
             </if>
         </trim>
     </insert>
+
+
+    <select id="getPCLChartCount" resultType="java.lang.Integer" parameterType="com.ygj.yuemum.domain.promotion.PromotionChannelLog" >
+        SELECT
+            count(1)
+        FROM
+	      promotion_channel_log
+	    where 1=1
+        <if test="pcl_channel_code != null and pcl_channel_code != ''">
+            and pcl_channel_code = #{pcl_channel_code,jdbcType=VARCHAR}
+        </if>
+        <if test="pcl_date != null and pcl_date != ''">
+            and DATE_FORMAT(pcl_date, '%Y-%m-%d')  =  #{pcl_date,jdbcType=DATE}
+        </if>
+    </select>
+
+    <select id="getPCLChartDate" resultType="com.ygj.yuemum.domain.promotion.PromotionChannelLogDate" >
+        SELECT
+            max(
+                DATE_FORMAT(pcl_date, '%Y-%m-%d')
+            ) pcl_date_max,
+            min(
+                DATE_FORMAT(pcl_date, '%Y-%m-%d')
+            ) pcl_date_min
+        FROM
+            promotion_channel_log
+    </select>
+
+    <select id="getPromotionChannelCharts" resultType="com.ygj.yuemum.domain.promotion.PromotionChannelLog" parameterType="com.ygj.yuemum.domain.promotion.PromotionChannelLog" >
+        SELECT DISTINCT
+        (pcl_channel_code) pcl_channel_code,
+        fgetPChannelname(pcl_channel_code) pcl_channel_name
+        FROM
+        promotion_channel_log
+        where 1=1
+        <if test="pcl_channel_code != null and pcl_channel_code != ''">
+            and pcl_channel_code = #{pcl_channel_code,jdbcType=VARCHAR}
+        </if>
+        <if test="prx_id != null and prx_id != ''">
+            and prx_id = #{prx_id,jdbcType=INTEGER}
+        </if>
+    </select>
+
+
+
 </mapper>

+ 2 - 0
src/main/resources/mybatis/mapper/promotion/PromotionChannelMapper.xml

@@ -4,6 +4,7 @@
 
     <resultMap id="BaseResultMap" type="com.ygj.yuemum.domain.promotion.PromotionChannel" >
         <id column="id" property="id" jdbcType="INTEGER" />
+        <result column="pc_code" property="pc_code" jdbcType="VARCHAR" />
         <result column="pc_name" property="pc_name" jdbcType="VARCHAR" />
     </resultMap>
 
@@ -15,4 +16,5 @@
         order by 1 desc
     </select>
 
+
 </mapper>