Bladeren bron

后台首页统计

李书文 1 jaar geleden
bovenliggende
commit
d4e86d7642

+ 16 - 1
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersController.java

@@ -84,7 +84,22 @@ public class TbOrdersController {
 		return AjaxJson.getByLine(line);
 	}
 
+	/** 查询所有统计年份 **/
+	@RequestMapping("selectYear")
+	public AjaxJson selectYear() {
+		SoMap so=new SoMap();
+		so.put("year",tbOrdersService.selectYear());
+		so.put("count",tbOrdersService.totalMoney());
+		return AjaxJson.getSuccessData(so);
+	}
 
-
+	/** 根据年份查询每月订单交易额统计 **/
+	@RequestMapping("orderStatistics")
+	public AjaxJson orderStatistics(String year) {
+		SoMap so=new SoMap();
+		so.put("money",tbOrdersService.orderStatistics("交易额",year));
+		so.put("count",tbOrdersService.orderStatistics("交易量",year));
+		return AjaxJson.getSuccessData(so);
+	}
 
 }

+ 8 - 2
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersMapper.java

@@ -1,11 +1,13 @@
 package com.pj.tb_orders;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.ibatis.annotations.Mapper;
 
 import com.pj.utils.so.*;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 /**
@@ -17,8 +19,6 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface TbOrdersMapper extends BaseMapper <TbOrders> {
 
-
-
 	/**
 	 * 查集合 - 根据条件(参数为空时代表忽略指定条件)
 	 * @param so 参数集合
@@ -33,4 +33,10 @@ public interface TbOrdersMapper extends BaseMapper <TbOrders> {
 	List<TbOrders> getList();
 
 	List<TbOrders> getLevelTwoList(SoMap so);
+
+	List<Map<String, Object>> orderStatistics(@Param("type") String type,@Param("year") String year);
+
+	List<Map<String, Object>> selectYear();
+
+	Map<String, Object> totalMoney();
 }

+ 44 - 6
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersMapper.xml

@@ -96,11 +96,49 @@
 		<if test=' this.has("goodsName") '>and goods_name like concat('%', #{goodsName}, '%') or ve_no like upper(concat('%', #{goodsName}, '%'))</if>
 	</select>
 
-
-
-
-
-
-
+	<!--已完成和累计交易额 -->
+	<select id="totalMoney" resultType="java.util.Map">
+		SELECT
+				( SELECT SUM( resale_price ) FROM tb_orders ) AS totalMoney,
+				( SELECT SUM( resale_price )  FROM tb_orders WHERE order_finish=1) AS finishMoney,
+				( SELECT COUNT(id)  FROM tb_orders) AS orders
+	</select>
+	<!--查询所有统计年份 -->
+	<select id="selectYear" resultType="java.util.Map">
+		SELECT YEAR(create_time) AS year FROM tb_orders GROUP BY YEAR(create_time) ORDER BY year
+	</select>
+	<!--根据年份查询每月订单交易额和交易量统计 -->
+	<select id="orderStatistics" resultType="java.util.Map">
+		SELECT
+			months.month AS name,
+		    <if test="type=='交易额'">
+			SUM(tb_orders.resale_price) AS value
+			</if>
+		    <if test="type=='交易量'">
+			COUNT(tb_orders.id) AS value
+			</if>
+		FROM
+			(
+			SELECT 1 AS month UNION ALL
+			SELECT 2 AS month UNION ALL
+			SELECT 3 AS month UNION ALL
+			SELECT 4 AS month UNION ALL
+			SELECT 5 AS month UNION ALL
+			SELECT 6 AS month UNION ALL
+			SELECT 7 AS month UNION ALL
+			SELECT 8 AS month UNION ALL
+			SELECT 9 AS month UNION ALL
+			SELECT 10 AS month UNION ALL
+			SELECT 11 AS month UNION ALL
+			SELECT 12 AS month
+			) AS months
+			LEFT JOIN
+			tb_orders ON
+			MONTH(tb_orders.create_time) = months.month AND YEAR(tb_orders.create_time) =#{year}
+		GROUP BY
+			months.month
+		ORDER BY
+			months.month
+	</select>
 
 </mapper>

+ 27 - 4
sp-service/level-two-server/src/main/java/com/pj/tb_orders/TbOrdersService.java

@@ -36,10 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -419,4 +416,30 @@ public class TbOrdersService extends ServiceImpl<TbOrdersMapper, TbOrders> imple
 
         return true;
     }
+
+    /**
+     * 根据年份查询每月订单交易额和交易量统计
+     * @param type
+     * @param year
+     * @return
+     */
+    public List<Map<String, Object>> orderStatistics(String type,String year){
+        return tbOrdersMapper.orderStatistics(type,year);
+    }
+
+    /**
+     * 查询所有统计年份
+     * @return
+     */
+    public List<Map<String, Object>> selectYear(){
+        return tbOrdersMapper.selectYear();
+    }
+
+    /**
+     * 累计交易额
+     * @return
+     */
+    public Map<String, Object> totalMoney(){
+        return tbOrdersMapper.totalMoney();
+    }
 }

+ 8 - 0
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserController.java

@@ -145,5 +145,13 @@ public class AppUserController {
 		return account;
 	}
 
+	/**
+	 * 用户数量统计
+	 * @return
+	 */
+	@RequestMapping("selectUsers")
+	public AjaxJson selectUsers(){
+		return AjaxJson.getSuccessData(appUserService.selectUsers());
+	}
 
 }

+ 2 - 1
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserMapper.java

@@ -1,6 +1,7 @@
 package com.pj.project.app_user;
 
 import java.util.List;
+import java.util.Map;
 
 import org.apache.ibatis.annotations.Mapper;
 
@@ -26,5 +27,5 @@ public interface AppUserMapper extends BaseMapper <AppUser> {
 	 */
 	List<AppUser> getList(SoMap so);
 
-
+	Map<String, Object> selectUsers();
 }

+ 9 - 9
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserMapper.xml

@@ -54,14 +54,14 @@
 			<otherwise> id desc </otherwise>
 		</choose>
 	</select>
-	
-	
-	
-	
-	
-	
-	
-	
-	
+
+	<!--用户数量统计 -->
+	<select id="selectUsers" resultType="java.util.Map">
+		SELECT
+				( SELECT COUNT( id ) FROM app_user ) AS allUsers,
+				( SELECT COUNT( id ) FROM app_user WHERE user_type = 1 ) AS bm,
+				( SELECT COUNT( id ) FROM app_user WHERE user_type = 2 ) AS bmzz,
+				( SELECT COUNT( id ) FROM app_user WHERE user_type = 3 ) AS purchaser
+	</select>
 
 </mapper>

+ 8 - 1
sp-service/sp-admin/src/main/java/com/pj/project/app_user/AppUserService.java

@@ -3,6 +3,7 @@ package com.pj.project.app_user;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.Random;
 import java.util.stream.Collectors;
 
@@ -664,5 +665,11 @@ public class AppUserService extends ServiceImpl<AppUserMapper, AppUser> implemen
         return 1;
     }
 
-
+    /**
+     * 用户数量统计
+     * @return
+     */
+    public Map<String, Object> selectUsers(){
+        return appUserMapper.selectUsers();
+    };
 }