Преглед изворни кода

Merge branch 'master' of http://47.100.37.243:10080/wutt/game.git

quyueting пре 5 година
родитељ
комит
9afb085661

+ 48 - 0
minigame/WebContent/user_statistics.html

@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en" style="width: 100%">
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+    <meta http-equiv="X-UA-Compatible" content="ie=edge">
+    <title>用户地域统计</title>
+    <style type="text/css">
+    	*{
+    		margin: 0;
+    		padding: 0;
+    	}
+    </style>
+    <script src="js/jquery.min.js"></script>
+    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
+    <script type="text/javascript">
+	    $(function(){
+			$.post("./user/getUserOrderByCity", {}, function(resp) {
+				if (resp.code == 'error') {
+					console.log(resp.code);
+				}else{
+					for(let index in resp.data){
+					    var str = "<tr><td>" + (index + 1) + "</td><td>";
+					    if(resp.data[index].city == null || resp.data[index].city == ""){
+					        str += "未知</td><td>";
+                        }else{
+					        str += resp.data[index].city + "</td><td>";
+                        }
+                        str += resp.data[index].quantity + "</td></tr>"
+						$("table").append(str);
+					}
+				}
+			});
+		})
+	</script>
+</head>
+
+<body style="width: 100%">
+    <table class="table table-condensed">
+		<tr>
+			<th>#</th>
+			<th>地区</th>
+			<th>人数</th>
+		</tr>
+	</table>
+</body>
+</html>

+ 13 - 0
minigame/src/com/hssx/controller/UserController.java

@@ -206,6 +206,19 @@ public class UserController {
 		response.setCharacterEncoding("UTF-8");
 		response.getWriter().println(msg.toJSONStr());
 	}
+
+	/**
+	 * 根据区域返回用户数量
+	 * @param response
+	 */
+	@RequestMapping(value = "getUserOrderByCity")
+	public void getUserOrderByCity(HttpServletResponse response){
+		HttpRespMsg msg = new HttpRespMsg();
+		msg.data = usermapper.countUserGroupByCity();
+		response.setContentType("application/json");
+		response.setCharacterEncoding("UTF-8");
+		response.getWriter().println(msg.toJSONStr());
+	}
 	
 	/**
 	 * 获取微信JS config参数

+ 28 - 0
minigame/src/com/hssx/entity/vo/UserVO.java

@@ -0,0 +1,28 @@
+package com.hssx.entity.vo;
+
+import com.hssx.entity.User;
+
+public class UserVO extends User{
+
+    //城市
+    private String city;
+
+    //人数
+    private Integer quantity;
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public Integer getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(Integer quantity) {
+        this.quantity = quantity;
+    }
+}

+ 3 - 0
minigame/src/com/hssx/mapper/UserMapper.java

@@ -1,6 +1,7 @@
 package com.hssx.mapper;
 
 import com.hssx.entity.User;
+import com.hssx.entity.vo.UserVO;
 import com.hssx.entity.UserExample;
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
@@ -74,4 +75,6 @@ public interface UserMapper {
 	int updateByPrimaryKey(User record);
 
 	int insertUser(User u);
+
+	List<UserVO> countUserGroupByCity();
 }

+ 8 - 0
minigame/src/com/hssx/mapper/UserMapper.xml

@@ -15,6 +15,11 @@
     <result column="nick_name" jdbcType="VARCHAR" property="nickName" />
     <result column="city" jdbcType="VARCHAR" property="city" />
   </resultMap>
+  <!--根据城市返回人数的resultMap-->
+  <resultMap id="CityCountResultMap" type="com.hssx.entity.vo.UserVO">
+    <result column="city" jdbcType="VARCHAR" property="city" />
+    <result column="quantity" jdbcType="INTEGER" property="quantity" />
+  </resultMap>
   <sql id="Example_Where_Clause">
     <!--
       WARNING - @mbg.generated
@@ -315,4 +320,7 @@
       city = #{city,jdbcType=VARCHAR}
     where id = #{id,jdbcType=VARCHAR}
   </update>
+  <select id="countUserGroupByCity" parameterType="com.hssx.entity.UserExample" resultMap="CityCountResultMap">
+    SELECT city, COUNT(*) AS quantity FROM mini_user GROUP BY city;
+  </select>
 </mapper>

+ 1 - 1
minigame/src/jdbc.properties

@@ -5,7 +5,7 @@ driver=com.mysql.jdbc.Driver
 #password=VIz1iZK7i2n3eonT
 url=jdbc:mysql://118.190.47.230:3306/minigame?autoReconnect=true&rewriteBatchedStatements=TRUE&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8
 username=root
-password=p011430seya10
+password=p011430seya1026
 maxActive=255
 maxIdle=20
 maxWait=100