he2802 1 年之前
父節點
當前提交
26b8b31c0e

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

@@ -130,4 +130,20 @@ public class TopOrderStatisticsController extends BaseController {
     public AjaxResult<TopOrderTotalVo> getOrderTotal(TopOrderStatisticsBo bo) {
         return AjaxResult.success(iTopOldOrderService.getOrderTotal(bo));
     }
+
+    @ApiOperation("下单机构订单详情列表")
+    @GetMapping("/tenantDetailList")
+    public TableDataInfo<TopOrderStatisticsDetailVo> getTenantDetailList(TopOrderStatisticsBo bo) {
+        startPage();
+        List<TopOrderStatisticsDetailVo> list = iTopOldOrderService.getTenantDetailList(bo);
+        return getDataTable(list);
+    }
+
+    @ApiOperation("下单业务层次详情列表")
+    @GetMapping("/businessDetailList")
+    public TableDataInfo<TopOrderStatisticsDetailVo> getBusinessDetailList(TopOrderStatisticsBo bo) {
+        startPage();
+        List<TopOrderStatisticsDetailVo> list = iTopOldOrderService.getBusinessDetailList(bo);
+        return getDataTable(list);
+    }
 }

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

@@ -99,4 +99,8 @@ public interface TopOldOrderMapper extends BaseMapper<TopOldOrder> {
 
     List<TopOrderCustomerVo> getCustomerList();
 
+    List<TopOrderStatisticsDetailVo> getTenantDetailList(TopOrderStatisticsBo bo);
+
+    List<TopOrderStatisticsDetailVo> getBusinessDetailList(TopOrderStatisticsBo bo);
+
 }

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

@@ -173,4 +173,8 @@ public interface ITopOldOrderService extends IService<TopOldOrder> {
 	List<TopOrderCustomerVo> getCustomerList();
 
 	TopOrderTotalVo getOrderTotal(TopOrderStatisticsBo bo);
+
+	List<TopOrderStatisticsDetailVo> getTenantDetailList(TopOrderStatisticsBo bo);
+
+	List<TopOrderStatisticsDetailVo> getBusinessDetailList(TopOrderStatisticsBo bo);
 }

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

@@ -2422,7 +2422,7 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
             TopOrderStatisticsBo topOrderStatisticsBo = new TopOrderStatisticsBo();
             topOrderStatisticsBo.setStartTime(startTime - time);
             topOrderStatisticsBo.setEndTime(startTime);
-            topOrderStatisticsBo.setCustomerId(item.getCustomerId());
+            topOrderStatisticsBo.setTenantId(item.getTenantId());
             Long num = baseMapper.getSingleTenantStatisticsOrderNum(topOrderStatisticsBo);
             if (num > 0){
                 Long subtract = item.getOrderNum() - num;
@@ -2607,7 +2607,7 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
                 if (num > 0){
                     Long subtract = item.getOrderNum() - num;
                     BigDecimal divide = new BigDecimal(subtract).divide(new BigDecimal(num),2, RoundingMode.HALF_UP);
-                    item.setWeekRate(divide.multiply(new BigDecimal("100")));
+                    item.setYearRate(divide.multiply(new BigDecimal("100")));
                 }
             }
 
@@ -3194,6 +3194,224 @@ public class TopOldOrderServiceImpl extends ServiceImpl<TopOldOrderMapper, TopOl
         return resultVo;
     }
 
+    @Override
+    public List<TopOrderStatisticsDetailVo> getTenantDetailList(TopOrderStatisticsBo 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;
+            }
+        }
+
+        List<TopOrderStatisticsDetailVo> detailVos = baseMapper.getTenantDetailList(bo);
+        if (CollectionUtils.isEmpty(detailVos)){
+            return new ArrayList<>();
+        }
+
+        //订单总额
+        BigDecimal moneyTotal = baseMapper.getMoneyStatisticsWithBo(bo);
+        //订单总数量
+        Long numTotal = baseMapper.getNumStatisticsTotalWithBo(bo);
+        detailVos.forEach(item -> {
+            //订单客户机构ID
+
+            if (item.getMoney().compareTo(BigDecimal.ZERO) == 0){
+                return;
+            }
+            //订单金额
+            //环比
+            Long startTime = bo.getStartTime();
+            Long endTime = bo.getEndTime();
+            Long time = endTime - startTime;
+            TopOrderStatisticsBo topOrderStatisticsBo = new TopOrderStatisticsBo();
+            topOrderStatisticsBo.setStartTime(startTime - time);
+            topOrderStatisticsBo.setEndTime(startTime);
+            topOrderStatisticsBo.setCreateNo(item.getCreateNo());
+            topOrderStatisticsBo.setTenantId(item.getTenantId().toString());
+            BigDecimal money = baseMapper.getSingleTenantStatistics(topOrderStatisticsBo);
+            if (money.compareTo(BigDecimal.ZERO) > 0){
+                BigDecimal subtract = item.getMoney().subtract(money);
+                BigDecimal divide = subtract.divide(money,2, RoundingMode.HALF_UP);
+                item.setMoneyWeekRate(divide.multiply(new BigDecimal("100")));
+            }
+            Long num = baseMapper.getSingleTenantStatisticsOrderNum(topOrderStatisticsBo);
+            if (num > 0){
+                Long subtract = item.getOrderNum() - num;
+                BigDecimal divide = new BigDecimal(subtract).divide(new BigDecimal(num),2, RoundingMode.HALF_UP);
+                item.setWeekRate(divide.multiply(new BigDecimal("100")));
+            }
+
+
+            //同比
+            Long startBefore = DateUtils.getDayBefore(bo.getStartTime(), 365);
+            Long endBefore = DateUtils.getDayBefore(bo.getEndTime(), 365);
+            topOrderStatisticsBo.setStartTime(startBefore);
+            topOrderStatisticsBo.setEndTime(endBefore);
+            BigDecimal money2 = baseMapper.getSingleTenantStatistics(topOrderStatisticsBo);
+            if (money2.compareTo(BigDecimal.ZERO) > 0){
+                BigDecimal subtract = item.getMoney().subtract(money2);
+                BigDecimal divide = subtract.divide(money2,2, RoundingMode.HALF_UP);
+                item.setMoneyYearRate(divide.multiply(new BigDecimal("100")));
+            }
+
+
+            //同比
+            Long num2 = baseMapper.getSingleTenantStatisticsOrderNum(topOrderStatisticsBo);
+            if (num2 > 0){
+                Long subtract = item.getOrderNum() - num2;
+                BigDecimal divide = new BigDecimal(subtract).divide(new BigDecimal(num2),2, RoundingMode.HALF_UP);
+                item.setWeekRate(divide.multiply(new BigDecimal("100")));
+            }
+
+            //金额占比
+            BigDecimal divide = item.getMoney().divide(moneyTotal, 2, RoundingMode.HALF_UP);
+            String s = divide.multiply(new BigDecimal("100")).toString();
+            item.setMoneyOccupationRate(s+"%");
+            //数量占比
+            BigDecimal divide2 = new BigDecimal(item.getOrderNum()).divide(new BigDecimal(numTotal), 2, RoundingMode.HALF_UP);
+            String s2 = divide2.multiply(new BigDecimal("100")).toString();
+            item.setOccupationRate(s2+"%");
+        });
+        return detailVos;
+    }
+
+    @Override
+    public List<TopOrderStatisticsDetailVo> getBusinessDetailList(TopOrderStatisticsBo 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;
+            }
+        }
+
+        List<TopOrderStatisticsDetailVo> detailVos = baseMapper.getBusinessDetailList(bo);
+        if (CollectionUtils.isEmpty(detailVos)){
+            return new ArrayList<>();
+        }
+
+        //订单总额
+        BigDecimal moneyTotal = baseMapper.getMoneyStatisticsWithBo(bo);
+        //订单总数量
+        Long numTotal = baseMapper.getOrderGoodsNumStatisticsTotalWithBo(bo);
+        detailVos.forEach(item -> {
+            //订单客户机构ID
+
+            if (item.getMoney().compareTo(BigDecimal.ZERO) == 0){
+                return;
+            }
+            //订单金额
+            //环比
+            Long startTime = bo.getStartTime();
+            Long endTime = bo.getEndTime();
+            Long time = endTime - startTime;
+            TopOrderStatisticsBo topOrderStatisticsBo = new TopOrderStatisticsBo();
+            topOrderStatisticsBo.setStartTime(startTime - time);
+            topOrderStatisticsBo.setEndTime(startTime);
+            topOrderStatisticsBo.setCreateNo(item.getCreateNo());
+            topOrderStatisticsBo.setBusinessName(item.getBusinessName());
+            List<TopOrderStatisticsMoneyVo> moneyList1 = baseMapper.getBusinessOrderMoney(topOrderStatisticsBo);
+            if(moneyList1.size()>0){
+                BigDecimal money = moneyList1.get(0).getMoney();
+                if (money.compareTo(BigDecimal.ZERO) > 0){
+                    BigDecimal subtract = item.getMoney().subtract(money);
+                    BigDecimal divide = subtract.divide(money,2, RoundingMode.HALF_UP);
+                    item.setMoneyWeekRate(divide.multiply(new BigDecimal("100")));
+                }
+            }
+
+
+            List<TopOrderStatisticsNumVo> numStatistics = baseMapper.getBusinessOrderNum(topOrderStatisticsBo);
+            if (CollectionUtils.isNotEmpty(numStatistics)&&numStatistics.size()>0){
+                Long num = numStatistics.stream().findFirst().get().getOrderNum();
+                if (num > 0){
+                    Long subtract = item.getOrderNum() - num;
+                    BigDecimal divide = new BigDecimal(subtract).divide(new BigDecimal(num),2, RoundingMode.HALF_UP);
+                    item.setWeekRate(divide.multiply(new BigDecimal("100")));
+                }
+            }
+
+
+            //同比
+            Long startBefore = DateUtils.getDayBefore(bo.getStartTime(), 365);
+            Long endBefore = DateUtils.getDayBefore(bo.getEndTime(), 365);
+            topOrderStatisticsBo.setStartTime(startBefore);
+            topOrderStatisticsBo.setEndTime(endBefore);
+            List<TopOrderStatisticsMoneyVo> moneyList2 = baseMapper.getBusinessOrderMoney(topOrderStatisticsBo);
+            if(moneyList2.size()>0){
+                BigDecimal money2 = moneyList2.get(0).getMoney();
+                if (money2.compareTo(BigDecimal.ZERO) > 0){
+                    BigDecimal subtract = item.getMoney().subtract(money2);
+                    BigDecimal divide = subtract.divide(money2,2, RoundingMode.HALF_UP);
+                    item.setMoneyYearRate(divide.multiply(new BigDecimal("100")));
+                }
+            }
+
+            List<TopOrderStatisticsNumVo> numStatistics2 = baseMapper.getBusinessOrderNum(topOrderStatisticsBo);
+            if (CollectionUtils.isNotEmpty(numStatistics2)&&numStatistics2.size()>0){
+                Long num = numStatistics2.stream().findFirst().get().getOrderNum();
+                if (num > 0){
+                    Long subtract = item.getOrderNum() - num;
+                    BigDecimal divide = new BigDecimal(subtract).divide(new BigDecimal(num),2, RoundingMode.HALF_UP);
+                    item.setYearRate(divide.multiply(new BigDecimal("100")));
+                }
+            }
+
+            //金额占比
+            BigDecimal divide = item.getMoney().divide(moneyTotal, 2, RoundingMode.HALF_UP);
+            String s = divide.multiply(new BigDecimal("100")).toString();
+            item.setMoneyOccupationRate(s+"%");
+            //数量占比
+            BigDecimal divide2 = new BigDecimal(item.getOrderNum()).divide(new BigDecimal(numTotal), 2, RoundingMode.HALF_UP);
+            String s2 = divide2.multiply(new BigDecimal("100")).toString();
+            item.setOccupationRate(s2+"%");
+        });
+        return detailVos;
+    }
+
     private List<Long> getDayTime(Long startTime,Long endTime){
         List<Long> tiemList = new ArrayList<>();
         Long zeroTime = DateUtils.getScheduleTimeZeroTime(startTime);

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/order/vo/TopOrderStatisticsDetailVo.java

@@ -58,4 +58,7 @@ public class TopOrderStatisticsDetailVo implements Serializable {
     @ApiModelProperty("业务员名称")
     private String createUsername;
 
+    @ApiModelProperty("业务层次")
+    private String businessName;
+
 }

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/top/order/vo/TopOrderStatisticsNumVo.java

@@ -43,7 +43,7 @@ public class TopOrderStatisticsNumVo implements Serializable {
     @ApiModelProperty("企业ID")
     private String tenantId;
 
-    @ApiModelProperty("企业ID")
+    @ApiModelProperty("业务层次")
     private String businessName;
 
 }

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

@@ -1801,4 +1801,218 @@
         GROUP BY
             too.old_customer_id
     </select>
+
+    <select id="getTenantDetailList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
+            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
+        SELECT
+        vo.*,
+        st.tenant_name
+        FROM
+        (
+        SELECT
+        allu.tenant_id,
+        ANY_VALUE(allu.order_type) order_type,
+        SUM( allu.money2 ) money,
+        SUM(order_num2) order_num
+        <if test="tenantId != null and tenantId != ''">
+            , allu.create_no,allu.create_username
+        </if>
+        FROM
+        (
+        SELECT
+        tenant_id,
+        1 AS order_type,
+        SUM( order_received - order_refunded ) money2,
+        COUNT( * ) order_num2
+        <if test="tenantId != null and tenantId != ''">
+            , create_no,any_value(create_username) as create_username
+        </if>
+        FROM
+        top_old_order
+        WHERE
+        1 = 1
+        AND `status` = 1
+        AND check_status = 1
+        AND old_customer_id IS NOT NULL
+        <if test="startTime != null and startTime != ''">
+            AND check_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND check_time &lt;= #{endTime}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND tenant_id = #{tenantId}
+        </if>
+        <if test="customerId != null and customerId != ''">
+            AND tenant_id  = #{customerId}
+        </if>
+        AND tenant_id IS NOT NULL
+        GROUP BY
+        tenant_id
+        <if test="tenantId != null and tenantId != ''">
+            , create_no
+        </if>
+        UNION ALL
+        SELECT
+        og.tenant_id,
+        2 AS order_type,
+        IFNULL( SUM( og.goods_received ), 0 ) money2,
+        COUNT( * ) order_num2
+        <if test="tenantId != null and tenantId != ''">
+            ,'' AS create_no, '' as create_username
+        </if>
+        FROM
+        `order` o
+        LEFT JOIN `order_goods` `og` ON o.order_sn = og.order_sn
+        WHERE
+        o.`status` = 1
+        AND o.order_status = 1
+        AND og.refund_status != 2
+        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 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="customerId != null and customerId != ''">
+            AND o.tenant_id  = #{customerId}
+        </if>
+        AND o.tenant_id IS NOT NULL
+        AND og.pay_status != 1
+        GROUP BY
+        og.tenant_id
+        ) allu
+        GROUP BY
+        allu.tenant_id
+        <if test="tenantId != null and tenantId != ''">
+            , allu.create_no,allu.create_username
+        </if>
+        ORDER BY
+        tenant_id DESC
+        ) vo
+        LEFT JOIN sys_tenant st ON vo.tenant_id = st.tenant_id
+    </select>
+
+    <select id="getBusinessDetailList" parameterType="com.zhongzheng.modules.top.order.bo.TopOrderStatisticsBo"
+            resultType="com.zhongzheng.modules.top.order.vo.TopOrderStatisticsDetailVo">
+        SELECT
+        allu.business_name,
+        SUM( allu.money ) money,
+        SUM( allu.order_num ) order_num
+        FROM
+        (
+        SELECT
+        ouu.business_name,
+        IFNULL( SUM( oo.order_received - oo.order_refunded ), 0 ) money,
+        1 AS order_type,
+        COUNT( * ) order_num
+        FROM
+        (
+        SELECT
+        ou.order_sn,
+        ou.business_name
+        FROM
+        (
+        SELECT
+        `otg`.`order_sn` AS `order_sn`,
+        concat( substr( `otg`.`business_full_name`, 5, 4 ), '-', `otg`.`business_name` ) AS `business_name`
+        FROM
+        `top_old_order_goods` `otg`
+        ) ou
+        GROUP BY
+        ou.order_sn,
+        ou.business_name
+        ) ouu
+        LEFT JOIN top_old_order oo ON ouu.order_sn = oo.order_sn
+        WHERE
+        oo.`status` = 1
+        AND oo.check_status = 1
+        AND oo.old_customer_id IS NOT NULL
+        <if test="startTime != null and startTime != ''">
+            AND oo.check_time &gt;= #{startTime}
+        </if>
+        <if test="endTime != null and endTime != ''">
+            AND oo.check_time &lt;= #{endTime}
+        </if>
+        <if test="tenantId != null and tenantId != ''">
+            AND oo.tenant_id = #{tenantId}
+        </if>
+        <if test="createNo != null and createNo != ''">
+            AND oo.create_no = #{createNo}
+        </if>
+        <if test="businessName != null and businessName != ''">
+            AND ouu.business_name = #{businessName}
+        </if>
+        <if test="customerId != null and customerId != ''">
+            AND oo.tenant_id  = #{customerId}
+        </if>
+        GROUP BY
+        ouu.business_name UNION ALL
+        SELECT
+        nou.business_name,
+        SUM( nou.goods_received ) AS money,
+        2 AS order_type,
+        COUNT( * ) order_num
+        FROM
+        (
+        SELECT
+        `og`.`order_sn` AS `order_sn`,
+        concat( `cet`.`education_name`, '-', `cb`.`business_name`, `cpt`.`project_name` ) AS `business_name`,
+        og.goods_received
+        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
+        ) nou
+        WHERE 1=1
+        <if test="businessName != null and businessName != ''">
+            AND nou.business_name = #{businessName}
+        </if>
+        GROUP BY
+        nou.business_name
+        ) allu
+        GROUP BY
+        allu.business_name
+        ORDER BY
+        money DESC
+    </select>
 </mapper>