lcl 1 year ago
parent
commit
21f7d64c46

+ 11 - 5
src/main/java/com/kxs/adminap/controller/TestController.java

@@ -14,6 +14,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.kxs.adminap.config.Base;
 import com.kxs.adminap.dao.main.UserRankWhiteMapper;
 import com.kxs.adminap.enity.ListParam;
+import com.kxs.adminap.enity.RelationData;
 import com.kxs.adminap.model.main.UserAccount;
 import com.kxs.adminap.model.main.UserRankWhite;
 import com.kxs.adminap.model.main.Users;
@@ -69,13 +70,18 @@ public class TestController {
 		// result = new JwtUtil().generateToken("test");
 
 		result += Util.DateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + "<br>";
-		// Long count = 0L;
-		// List<Dictionary<String, Object>> obj = UsersService.List(new ArrayList<>(), " and Id<100",  count, 1, 20, "Id desc").get("list");
-		// result += JSONObject.toJSONString(obj) + "<br>";
-		// List<Users> user = UsersService.List(10, 10);
+		List<RelationData> relationDatas = new ArrayList<>();
+		RelationData relationData = new RelationData();
+		relationData.Field = "ParentUserId";
+		relationData.Table = "Users";
+		List<String> ReturnFields = new ArrayList<>();
+		ReturnFields.add("MakerCode");
+		ReturnFields.add("RealName");
+		relationData.ReturnField = ReturnFields;
 		Users data = new Users();
 		data.setMakerCode("K00000000");
-		Users user = UsersService.Query(data);
+		data.setRealName("客小爽");
+		List<Users> user = UsersService.List(relationDatas, data, " and Id<10", 1, 10, "Id desc");
 		result += JSONObject.toJSONString(user) + "<br>";
 		result += Util.DateFormat(new Date(), "yyyy-MM-dd HH:mm:ss.SSS") + "<br>";
 

+ 2 - 0
src/main/java/com/kxs/adminap/enity/ListParam.java

@@ -2,10 +2,12 @@
 
 import java.io.Serializable;
 import java.util.List;
+import java.util.Map;
 
 public class ListParam implements Serializable
 {
     public List<RelationData> relationData;
+    public Map<String, Object> query;
     public String condition;
     public Integer skip;
     public Integer limit;

+ 3 - 0
src/main/java/com/kxs/adminap/model/main/Users.java

@@ -4,6 +4,8 @@ import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+
 public class Users implements Serializable {
     private Integer id;
 
@@ -15,6 +17,7 @@ public class Users implements Serializable {
 
     private Integer version;
 
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createDate;
 
     private Date updateDate;

+ 5 - 7
src/main/java/com/kxs/adminap/service/main/UsersService.java

@@ -1,11 +1,6 @@
 package com.kxs.adminap.service.main;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Dictionary;
 import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
@@ -33,7 +28,7 @@ public class UsersService
     /// <param name="page">页码</param>
     /// <param name="limit">每页条数</param>
     /// <returns></returns>
-    public static List<Users> List(List<RelationData> relationData, String condition, Integer page, Integer limit, String orderBy)
+    public static List<Users> List(List<RelationData> relationData, Users query, String condition, Integer page, Integer limit, String orderBy)
     {
         SqlSession sqlSession = SqlSessionUtils.getSqlSession();
         UsersMapper usersMapper = sqlSession.getMapper(UsersMapper.class);
@@ -48,8 +43,10 @@ public class UsersService
         {
             param.skip = 0;
         }
+        param.relationData = relationData;
+        param.query = JSONObject.parseObject(JSONObject.toJSONString(query), Map.class);
         param.condition = condition;
-        param.field = "*";
+        param.field = "MakerCode,RealName,Mobile,CreateDate,AuthFlag,ParentUserIdForMakerCode,ParentUserIdForRealName";
         param.limit = limit;
         param.orderBy = orderBy;
         List<Users> result = usersMapper.selectAll(param);
@@ -76,6 +73,7 @@ public class UsersService
         SqlSession sqlSession = SqlSessionUtils.getSqlSession();
         UsersMapper usersMapper = sqlSession.getMapper(UsersMapper.class);
         Users result = usersMapper.selectByCondition(data);
+        if(result == null) result = new Users();
         sqlSession.close();
         return result;
     }

+ 21 - 1
src/main/resources/xml/main/UsersMapper.xml

@@ -269,8 +269,28 @@
     <if test="data.makerCode != null">
       and MakerCode = #{data.makerCode}
     </if>
+    <if test="data.realName != null">
+      and RealName = #{data.realName}
+    </if>
   </select>
   <select id="selectAll" parameterType="com.kxs.adminap.enity.ListParam" resultMap="BaseResultMap">
-    select ${field} from Users where 1=1${condition} order by ${orderBy} limit #{skip},#{limit}
+    select ${field}
+    <foreach collection="relationData" item="item" index="i">
+      <foreach collection="item.ReturnField" item="field">
+        ,#{item.table}#{i}.#{field} #{item.field}For#{field}
+      </foreach>
+    </foreach>
+     from Users 
+    <foreach collection="relationData" item="item" index="i">
+      left join #{item.table} #{item.table}#{i} on users.#{item.field}=#{item.table}#{i}.Id
+    </foreach>
+    where 1=1${condition} 
+    <if test="query.makerCode != null">
+      and MakerCode = #{query.makerCode}
+    </if>
+    <if test="query.realName != null">
+      and RealName = #{query.realName}
+    </if>
+    order by ${orderBy} limit #{skip},#{limit}
   </select>
 </mapper>