he2802 1 年之前
父節點
當前提交
ca32d060ae

+ 12 - 0
zhongzheng-admin-saas/src/main/java/com/zhongzheng/controller/order/TopOrderStatisticsController.java

@@ -146,4 +146,16 @@ public class TopOrderStatisticsController extends BaseController {
         List<TopOrderStatisticsDetailVo> list = iTopOldOrderService.getBusinessDetailList(bo);
         return getDataTable(list);
     }
+
+    @ApiOperation("机构走势图")
+    @GetMapping("/tenantView")
+    public AjaxResult<TopOrderStatisticsViewVo> getStatisticsTenantView(TopOrderStatisticsViewBo bo) {
+        return AjaxResult.success(iTopOldOrderService.getStatisticsTenantView(bo));
+    }
+
+    @ApiOperation("业务层次走势图")
+    @GetMapping("/businessView")
+    public AjaxResult<TopOrderStatisticsViewVo> getStatisticsBusinessView(TopOrderStatisticsViewBo bo) {
+        return AjaxResult.success(iTopOldOrderService.getStatisticsBusinessView(bo));
+    }
 }

+ 4 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/goods/mapper/TopOldOrderMapper.java

@@ -103,4 +103,8 @@ public interface TopOldOrderMapper extends BaseMapper<TopOldOrder> {
 
     List<TopOrderStatisticsDetailVo> getBusinessDetailList(TopOrderStatisticsBo bo);
 
+    List<TopOrderStatisticsTwoVo> getStatisticsTenantView(TopOrderStatisticsViewBo bo);
+
+    List<TopOrderStatisticsTwoVo> getStatisticsBusinessView(TopOrderStatisticsViewBo bo);
+
 }

+ 4 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/goods/service/ITopOldOrderService.java

@@ -179,4 +179,8 @@ public interface ITopOldOrderService extends IService<TopOldOrder> {
 	List<TopOrderStatisticsDetailVo> getBusinessDetailList(TopOrderStatisticsBo bo);
 
 	List<TopConversionRateTrendVo> getCustomerListData(TopOrderStatisticsBo bo);
+
+	TopOrderStatisticsViewVo getStatisticsTenantView(TopOrderStatisticsViewBo bo);
+
+	TopOrderStatisticsViewVo getStatisticsBusinessView(TopOrderStatisticsViewBo bo);
 }

+ 210 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/goods/service/impl/TopOldOrderServiceImpl.java

@@ -3493,6 +3493,216 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
         return trendVos;
     }
 
+    @Override
+    public TopOrderStatisticsViewVo getStatisticsTenantView(TopOrderStatisticsViewBo bo) {
+        //筛选时间处理
+        if (ObjectUtils.isNull(bo.getTimeSign()) && ObjectUtils.isNull(bo.getStartTime()) && ObjectUtils.isNull(bo.getEndTime())){
+            //没有选择时间范围,默认为当前时间向前推30天
+            Long nowTime = DateUtils.getNowTime();
+            Long dayBefore = DateUtils.getDayBefore(nowTime, 30);
+            bo.setStartTime(dayBefore);
+            bo.setEndTime(nowTime);
+        }else if (ObjectUtils.isNotNull(bo.getTimeSign())){
+            switch (bo.getTimeSign()){
+                case 1://本周
+                    Map<String, Long> timeInterval = DateUtils.getTimeInterval(new Date());
+                    bo.setStartTime(timeInterval.get("start"));
+                    bo.setEndTime(timeInterval.get("end"));
+                    break;
+                case 2://本月
+                    Long toMonthZeroTime = DateUtils.getToMonthZeroTime();
+                    bo.setStartTime(toMonthZeroTime);
+                    bo.setEndTime(DateUtils.getNowTime());
+                    break;
+                case 3://本年
+                    Long toYearZeroTime = DateUtils.getToYearZeroTime();
+                    bo.setStartTime(toYearZeroTime);
+                    bo.setEndTime(DateUtils.getNowTime());
+                    break;
+                default :
+                    break;
+            }
+        }
+        TopOrderStatisticsViewVo viewVo = new TopOrderStatisticsViewVo();
+        //天
+        bo.setViewSign(1);
+        List<TopOrderStatisticsTwoVo> voList = baseMapper.getStatisticsTenantView(bo);
+        if (CollectionUtils.isNotEmpty(voList)){
+            List<Long> dayTime = getDayTime(bo.getStartTime(), bo.getEndTime());
+            List<TopOrderStatisticsTwoVo> vos = new ArrayList<>();
+            for (Long day : dayTime) {
+                TopOrderStatisticsTwoVo twoVo = new TopOrderStatisticsTwoVo();
+                twoVo.setTime(day);
+                twoVo.setTimeStr(DateUtils.timestampToDateFormat(day,"yyyy-MM-dd"));
+                if (voList.stream().anyMatch(x -> DateUtils.getScheduleTimeStrZeroTime(x.getTimeStr(), "yyyy-MM-dd").equals(day))){
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList.stream()
+                            .filter(x -> DateUtils.getScheduleTimeStrZeroTime(x.getTimeStr(), "yyyy-MM-dd").equals(day)).findFirst().get();
+                    twoVo.setMoney(statisticsTwoVo.getMoney());
+                    twoVo.setOrderNum(statisticsTwoVo.getOrderNum());
+                }
+                vos.add(twoVo);
+            }
+            viewVo.setDayView(vos);
+        }
+
+        //周
+        bo.setViewSign(2);
+        List<TopOrderStatisticsTwoVo> voList2 = baseMapper.getStatisticsTenantView(bo);
+        if (CollectionUtils.isNotEmpty(voList2)){
+            Map<Long, Long> weekTime = getWeekTime(bo.getStartTime(), bo.getEndTime());
+            List<TopOrderStatisticsTwoVo> vos = new ArrayList<>();
+            for (Long time : weekTime.keySet()) {
+                TopOrderStatisticsTwoVo twoVo = new TopOrderStatisticsTwoVo();
+                twoVo.setTime(time);
+                twoVo.setTimeStr(DateUtils.timestampToDateFormat(time,"yyyy-MM-dd"));
+                if (voList2.stream().anyMatch(x ->
+                        DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= weekTime.get(time))){
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList2.stream()
+                            .filter(x ->
+                                    DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                            && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= weekTime.get(time)).findFirst().get();
+                    twoVo.setMoney(statisticsTwoVo.getMoney());
+                    twoVo.setOrderNum(statisticsTwoVo.getOrderNum());
+                }
+                vos.add(twoVo);
+            }
+            viewVo.setWeekView(vos);
+        }
+
+        //月
+        bo.setViewSign(3);
+        List<TopOrderStatisticsTwoVo> voList3 = baseMapper.getStatisticsTenantView(bo);
+        if (CollectionUtils.isNotEmpty(voList3)){
+            Map<Long, Long> monthTime = DateUtils.getMonthTime(bo.getStartTime(), bo.getEndTime());
+            List<TopOrderStatisticsTwoVo> vos = new ArrayList<>();
+            for (Long time : monthTime.keySet()) {
+                TopOrderStatisticsTwoVo twoVo = new TopOrderStatisticsTwoVo();
+                twoVo.setTime(time);
+                twoVo.setTimeStr(DateUtils.timestampToDateFormat(time,"yyyy-MM"));
+                if (voList2.stream().anyMatch(x ->
+                        DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= monthTime.get(time))){
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList2.stream()
+                            .filter(x ->
+                                    DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                            && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= monthTime.get(time)).findFirst().get();
+                    twoVo.setMoney(statisticsTwoVo.getMoney());
+                    twoVo.setOrderNum(statisticsTwoVo.getOrderNum());
+                }
+                vos.add(twoVo);
+            }
+            viewVo.setMonthView(vos);
+        }
+
+        return viewVo;
+    }
+
+    @Override
+    public TopOrderStatisticsViewVo getStatisticsBusinessView(TopOrderStatisticsViewBo bo) {
+        //筛选时间处理
+        if (ObjectUtils.isNull(bo.getTimeSign()) && ObjectUtils.isNull(bo.getStartTime()) && ObjectUtils.isNull(bo.getEndTime())){
+            //没有选择时间范围,默认为当前时间向前推30天
+            Long nowTime = DateUtils.getNowTime();
+            Long dayBefore = DateUtils.getDayBefore(nowTime, 30);
+            bo.setStartTime(dayBefore);
+            bo.setEndTime(nowTime);
+        }else if (ObjectUtils.isNotNull(bo.getTimeSign())){
+            switch (bo.getTimeSign()){
+                case 1://本周
+                    Map<String, Long> timeInterval = DateUtils.getTimeInterval(new Date());
+                    bo.setStartTime(timeInterval.get("start"));
+                    bo.setEndTime(timeInterval.get("end"));
+                    break;
+                case 2://本月
+                    Long toMonthZeroTime = DateUtils.getToMonthZeroTime();
+                    bo.setStartTime(toMonthZeroTime);
+                    bo.setEndTime(DateUtils.getNowTime());
+                    break;
+                case 3://本年
+                    Long toYearZeroTime = DateUtils.getToYearZeroTime();
+                    bo.setStartTime(toYearZeroTime);
+                    bo.setEndTime(DateUtils.getNowTime());
+                    break;
+                default :
+                    break;
+            }
+        }
+        TopOrderStatisticsViewVo viewVo = new TopOrderStatisticsViewVo();
+        //天
+        bo.setViewSign(1);
+        List<TopOrderStatisticsTwoVo> voList = baseMapper.getStatisticsBusinessView(bo);
+        if (CollectionUtils.isNotEmpty(voList)){
+            List<Long> dayTime = getDayTime(bo.getStartTime(), bo.getEndTime());
+            List<TopOrderStatisticsTwoVo> vos = new ArrayList<>();
+            for (Long day : dayTime) {
+                TopOrderStatisticsTwoVo twoVo = new TopOrderStatisticsTwoVo();
+                twoVo.setTime(day);
+                twoVo.setTimeStr(DateUtils.timestampToDateFormat(day,"yyyy-MM-dd"));
+                if (voList.stream().anyMatch(x -> DateUtils.getScheduleTimeStrZeroTime(x.getTimeStr(), "yyyy-MM-dd").equals(day))){
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList.stream()
+                            .filter(x -> DateUtils.getScheduleTimeStrZeroTime(x.getTimeStr(), "yyyy-MM-dd").equals(day)).findFirst().get();
+                    twoVo.setMoney(statisticsTwoVo.getMoney());
+                    twoVo.setOrderNum(statisticsTwoVo.getOrderNum());
+                }
+                vos.add(twoVo);
+            }
+            viewVo.setDayView(vos);
+        }
+
+        //周
+        bo.setViewSign(2);
+        List<TopOrderStatisticsTwoVo> voList2 = baseMapper.getStatisticsBusinessView(bo);
+        if (CollectionUtils.isNotEmpty(voList2)){
+            Map<Long, Long> weekTime = getWeekTime(bo.getStartTime(), bo.getEndTime());
+            List<TopOrderStatisticsTwoVo> vos = new ArrayList<>();
+            for (Long time : weekTime.keySet()) {
+                TopOrderStatisticsTwoVo twoVo = new TopOrderStatisticsTwoVo();
+                twoVo.setTime(time);
+                twoVo.setTimeStr(DateUtils.timestampToDateFormat(time,"yyyy-MM-dd"));
+                if (voList2.stream().anyMatch(x ->
+                        DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= weekTime.get(time))){
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList2.stream()
+                            .filter(x ->
+                                    DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                            && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= weekTime.get(time)).findFirst().get();
+                    twoVo.setMoney(statisticsTwoVo.getMoney());
+                    twoVo.setOrderNum(statisticsTwoVo.getOrderNum());
+                }
+                vos.add(twoVo);
+            }
+            viewVo.setWeekView(vos);
+        }
+
+        //月
+        bo.setViewSign(3);
+        List<TopOrderStatisticsTwoVo> voList3 = baseMapper.getStatisticsBusinessView(bo);
+        if (CollectionUtils.isNotEmpty(voList3)){
+            Map<Long, Long> monthTime = DateUtils.getMonthTime(bo.getStartTime(), bo.getEndTime());
+            List<TopOrderStatisticsTwoVo> vos = new ArrayList<>();
+            for (Long time : monthTime.keySet()) {
+                TopOrderStatisticsTwoVo twoVo = new TopOrderStatisticsTwoVo();
+                twoVo.setTime(time);
+                twoVo.setTimeStr(DateUtils.timestampToDateFormat(time,"yyyy-MM"));
+                if (voList2.stream().anyMatch(x ->
+                        DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= monthTime.get(time))){
+                    TopOrderStatisticsTwoVo statisticsTwoVo = voList2.stream()
+                            .filter(x ->
+                                    DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) >= time
+                                            && DateUtils.getScheduleTimeZeroTime(x.getOrderTime()) <= monthTime.get(time)).findFirst().get();
+                    twoVo.setMoney(statisticsTwoVo.getMoney());
+                    twoVo.setOrderNum(statisticsTwoVo.getOrderNum());
+                }
+                vos.add(twoVo);
+            }
+            viewVo.setMonthView(vos);
+        }
+
+        return viewVo;
+    }
+
     private List<Long> getDayTime(Long startTime,Long endTime){
         List<Long> tiemList = new ArrayList<>();
         Long zeroTime = DateUtils.getScheduleTimeZeroTime(startTime);

+ 8 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/order/bo/TopOrderStatisticsViewBo.java

@@ -31,4 +31,12 @@ public class TopOrderStatisticsViewBo implements Serializable {
 
     @ApiModelProperty("业务层次")
     private String businessName;
+
+    @ApiModelProperty("企业ID")
+    private String tenantId;
+
+    @ApiModelProperty("业务号")
+    private String createNo;
+
+
 }

+ 182 - 0
zhongzheng-system/src/main/resources/mapper/modules/top/TopOldOrderMapper.xml

@@ -2015,4 +2015,186 @@
         ORDER BY
         money DESC
     </select>
+
+    <select id="getStatisticsTenantView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
+            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
+        SELECT
+        COUNT(a.order_id) AS orderNum,
+        SUM(a.money) AS money,
+        any_value(a.timeStr) AS orderTime,
+        <if test="viewSign != null and viewSign == 1">
+            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
+        </if>
+        <if test="viewSign != null and viewSign == 2">
+            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
+        </if>
+        <if test="viewSign != null and viewSign == 3">
+            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
+        </if>
+        FROM (
+        SELECT
+        too.order_id as order_id,
+        too.check_time as timeStr,
+        too.order_received - too.order_refunded as money
+        FROM
+        top_old_order too
+        WHERE
+        too.`status` = 1
+        AND too.check_status = 1
+        <if test="startTime != null and startTime != ''">
+            AND too.check_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND too.check_time &lt;= #{endTime}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND too.tenant_id = #{tenantId}
+        </if>
+        <if test="createNo != null and createNo != ''">
+            AND too.create_no = #{createNo}
+        </if>
+        UNION ALL
+        SELECT
+        o.order_id as order_id,
+        o.create_time as timeStr,
+        o.order_price as money
+        FROM
+        `order` o
+        WHERE
+        o.`status` = 1
+        AND o.order_status = 1
+        AND (
+        o.input_order_sn IS NULL
+        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) = 0
+        )
+        <if test="startTime != null and startTime != ''">
+            AND o.create_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND o.create_time &lt;= #{endTime}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND o.tenant_id = #{tenantId}
+        </if>
+        <if test="createNo != null and createNo != ''">
+            AND o.create_no = #{createNo}
+        </if>
+        ) a WHERE 1=1
+        <if test="viewSign != null and viewSign == 1">
+            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
+        </if>
+        <if test="viewSign != null and viewSign == 2">
+            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
+        </if>
+        <if test="viewSign != null and viewSign == 3">
+            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
+        </if>
+    </select>
+
+    <select id="getStatisticsBusinessView" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsViewBo"
+            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsTwoVo">
+        SELECT
+        COUNT(a.order_sn) AS orderNum,
+        SUM(a.money) AS money,
+        any_value(a.timeStr) AS orderTime,
+        <if test="viewSign != null and viewSign == 1">
+            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d') AS timeStr
+        </if>
+        <if test="viewSign != null and viewSign == 2">
+            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U') AS timeStr
+        </if>
+        <if test="viewSign != null and viewSign == 3">
+            DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m') AS timeStr
+        </if>
+        FROM (
+        SELECT
+        too.order_sn,
+        concat(
+        substr(( SELECT otg.business_full_name FROM `top_old_order_goods` `otg` WHERE otg.order_sn = too.order_sn LIMIT 1 ), 5, 4 ),
+        '-',(
+        SELECT
+        otg.business_name
+        FROM
+        `top_old_order_goods` `otg`
+        WHERE
+        otg.order_sn = too.order_sn
+        LIMIT 1
+        )
+        ) AS `business_name`,
+        too.order_received - too.order_refunded AS money,
+        too.check_time as timeStr
+        FROM
+        top_old_order too
+        WHERE
+        too.`status` = 1
+        AND too.check_status = 1
+        <if test="startTime != null and startTime != ''">
+            AND too.check_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND too.check_time &lt;= #{endTime}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND too.tenant_id = #{tenantId}
+        </if>
+        <if test="createNo != null and createNo != ''">
+            AND too.create_no = #{createNo}
+        </if>
+        UNION ALL
+        SELECT
+        `og`.`order_sn` AS `order_sn`,
+        concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
+        og.goods_received as money,
+        og.create_time as timeStr
+        FROM
+        ((((
+        `order` o
+        LEFT JOIN  `order_goods` `og` ON o.order_sn = og.order_sn
+        LEFT JOIN `goods` `g` ON ((
+        `og`.`goods_id` = `g`.`goods_id`
+        )))
+        LEFT JOIN `course_education_type` `cet` ON ((
+        `g`.`education_type_id` = `cet`.`id`
+        )))
+        LEFT JOIN `course_project_type` `cpt` ON ((
+        `g`.`education_type_id` = `cpt`.`id`
+        )))
+        LEFT JOIN `course_business` `cb` ON ((
+        `g`.`business_id` = `cb`.`id`
+        )))
+        WHERE
+        og.pay_status != 1
+        AND (
+        o.input_order_sn IS NULL
+        OR ( SELECT COUNT( too.order_id ) FROM top_old_order too WHERE too.input_order_sn = o.input_order_sn ) &lt; 1 ) AND o.tenant_id IS NOT NULL
+        <if test="startTime != null and startTime != ''">
+            AND og.create_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND og.create_time &lt;= #{endTime}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND og.tenant_id = #{tenantId}
+        </if>
+        <if test="createNo != null and createNo != ''">
+            AND 1=0
+        </if>
+        <if test="customerId != null and customerId != ''">
+            AND og.tenant_id  = #{customerId}
+        </if>
+        AND og.refund_status != 2
+        ) a WHERE 1=1
+        <if test="businessName != null and businessName != ''">
+            AND a.business_name = #{businessName}
+        </if>
+        <if test="viewSign != null and viewSign == 1">
+            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m-%d')
+        </if>
+        <if test="viewSign != null and viewSign == 2">
+            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%U')
+        </if>
+        <if test="viewSign != null and viewSign == 3">
+            GROUP BY DATE_FORMAT(FROM_UNIXTIME(a.timeStr), '%Y-%m')
+        </if>
+    </select>
 </mapper>