Browse Source

sys_user ok

mgr-gxzc 7 years ago
parent
commit
4d6fa08767

+ 1 - 4
build.gradle

@@ -104,12 +104,9 @@ subprojects {
         compile ("com.google.guava:guava:23.6-jre")
         compile ("com.github.penggle:kaptcha:2.3.2")
         compile ("com.alibaba:fastjson:$fastjson_version")
-        compile ("com.fasterxml.jackson.core:jackson-core:2.9.3")
-        compile ("com.fasterxml.jackson.core:jackson-databind:2.9.3")
-        compile ("com.fasterxml.jackson.core:jackson-annotations:2.9.3")
 
 
-        compile ("com.baomidou:kisso:3.6.11")
+        compile ("com.baomidou:kisso:3.7.0")
         compile ("io.jsonwebtoken:jjwt:0.7.0")
         compile ("org.projectlombok:lombok:1.16.18")
     }

+ 10 - 0
doc/数据库必备字段.sql

@@ -0,0 +1,10 @@
+ALTER TABLE `userdata`
+ADD COLUMN `id`  bigint(20) NOT NULL AUTO_INCREMENT COMMENT '系统编号',
+ADD COLUMN `create_by`  varchar(64) NULL DEFAULT NULL COMMENT '创建者',
+ADD COLUMN `create_time`  datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+ADD COLUMN `update_by`  varchar(64) NULL DEFAULT NULL COMMENT '更新者',
+ADD COLUMN `update_time`  datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
+ADD COLUMN `remark`  varchar(255) NULL DEFAULT NULL COMMENT '备注信息',
+ADD COLUMN `enable`  char(1) NOT NULL DEFAULT '1' COMMENT '启用标记',
+-- DROP PRIMARY KEY,
+ADD PRIMARY KEY (`id`);

+ 0 - 1
zen-admin/src/main/kotlin/com/gxzc/zen/ExampleController.kt

@@ -1,6 +1,5 @@
 package com.gxzc.zen
 
-import com.gxzc.zen.sys.dao.TestDao
 import com.gxzc.zen.sys.service.TestService
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.ui.Model

+ 8 - 0
zen-api/src/main/kotlin/com/gxzc/zen/sys/dao/TSysUserDao.kt

@@ -0,0 +1,8 @@
+package com.gxzc.zen.sys.dao
+
+import com.gxzc.zen.persistence.ZenBaseDao
+import com.gxzc.zen.sys.model.TSysUser
+import org.springframework.stereotype.Repository
+
+@Repository
+interface TSysUserDao : ZenBaseDao<TSysUser>

+ 15 - 0
zen-api/src/main/kotlin/com/gxzc/zen/sys/model/TSysUser.kt

@@ -0,0 +1,15 @@
+package com.gxzc.zen.sys.model
+
+import com.gxzc.zen.persistence.ZenBaseModel
+import java.util.*
+
+class TSysUser:ZenBaseModel(){
+    var account:String?=null
+    var password:String?=null
+    var userType:Date?=null
+    var name:String?=null
+    var phone:String?=null
+    var deptId:Long?=null
+    var avatar:String?=null
+    var staffNo:String?=null
+}

+ 12 - 0
zen-api/src/main/kotlin/com/gxzc/zen/sys/service/TSysUserService.kt

@@ -0,0 +1,12 @@
+package com.gxzc.zen.sys.service
+
+import com.gxzc.zen.persistence.ZenBaseService
+import com.gxzc.zen.sys.dao.TSysUserDao
+import com.gxzc.zen.sys.dao.TestDao
+import com.gxzc.zen.sys.model.TSysUser
+import com.gxzc.zen.sys.model.Test
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.stereotype.Service
+
+@Service
+class TSysUserService:ZenBaseService<TSysUser, TSysUserDao>()

+ 15 - 0
zen-api/src/main/resources/com/gxzc/zen/mapping/sys/TSysUserMapper.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.gxzc.zen.sys.dao.TSysUserDao">
+
+    <select id="findList" resultType="com.gxzc.zen.sys.model.TSysUser">
+        SELECT *
+        FROM t_sys_user
+        <where>
+            <if test="cm.account!=null and cm.account!=''">
+                and account=#{cm.account}
+            </if>
+        </where>
+    </select>
+
+</mapper>

+ 151 - 0
zen-common/src/main/java/com/gxzc/zen/plug/Encodes.java

@@ -0,0 +1,151 @@
+/**
+ * Copyright (c) 2005-2012 springside.org.cn
+ */
+package com.gxzc.zen.plug;
+
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.lang3.StringEscapeUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+
+/**
+ * 封装各种格式的编码解码工具类.
+ * 1.Commons-Codec的 hex/base64 编码
+ * 2.自制的base62 编码
+ * 3.Commons-Lang的xml/html escape
+ * 4.JDK提供的URLEncoder
+ * @author calvin
+ * @version 2013-01-15
+ */
+public class Encodes {
+
+	private static final String DEFAULT_URL_ENCODING = "UTF-8";
+	private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
+
+	/**
+	 * Hex编码.
+	 */
+	public static String encodeHex(byte[] input) {
+		return new String(Hex.encodeHex(input));
+	}
+
+	/**
+	 * Hex解码.
+	 */
+	public static byte[] decodeHex(String input) {
+		try {
+			return Hex.decodeHex(input.toCharArray());
+		} catch (DecoderException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * Base64编码.
+	 */
+	public static String encodeBase64(byte[] input) {
+		return new String(Base64.encodeBase64(input));
+	}
+	
+	/**
+	 * Base64编码.
+	 */
+	public static String encodeBase64(String input) {
+		try {
+			return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
+		} catch (UnsupportedEncodingException e) {
+			return "";
+		}
+	}
+
+//	/**
+//	 * Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548).
+//	 */
+//	public static String encodeUrlSafeBase64(byte[] input) {
+//		return Base64.encodeBase64URLSafe(input);
+//	}
+
+	/**
+	 * Base64解码.
+	 */
+	public static byte[] decodeBase64(String input) {
+		return Base64.decodeBase64(input.getBytes());
+	}
+	
+	/**
+	 * Base64解码.
+	 */
+	public static String decodeBase64String(String input) {
+		try {
+			return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
+		} catch (UnsupportedEncodingException e) {
+			return "";
+		}
+	}
+
+	/**
+	 * Base62编码。
+	 */
+	public static String encodeBase62(byte[] input) {
+		char[] chars = new char[input.length];
+		for (int i = 0; i < input.length; i++) {
+			chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)];
+		}
+		return new String(chars);
+	}
+
+	/**
+	 * Html 转码.
+	 */
+	public static String escapeHtml(String html) {
+		return StringEscapeUtils.escapeHtml4(html);
+	}
+
+	/**
+	 * Html 解码.
+	 */
+	public static String unescapeHtml(String htmlEscaped) {
+		return StringEscapeUtils.unescapeHtml4(htmlEscaped);
+	}
+
+	/**
+	 * Xml 转码.
+	 */
+	public static String escapeXml(String xml) {
+		return StringEscapeUtils.escapeXml10(xml);
+	}
+
+	/**
+	 * Xml 解码.
+	 */
+	public static String unescapeXml(String xmlEscaped) {
+		return StringEscapeUtils.unescapeXml(xmlEscaped);
+	}
+
+	/**
+	 * URL 编码, Encode默认为UTF-8. 
+	 */
+	public static String urlEncode(String part) {
+		try {
+			return URLEncoder.encode(part, DEFAULT_URL_ENCODING);
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * URL 解码, Encode默认为UTF-8. 
+	 */
+	public static String urlDecode(String part) {
+
+		try {
+			return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e);
+		}
+	}
+}

+ 41 - 0
zen-common/src/main/java/com/gxzc/zen/plug/IdGen.java

@@ -0,0 +1,41 @@
+/**
+ * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
+ */
+package com.gxzc.zen.plug;
+
+import java.security.SecureRandom;
+import java.util.UUID;
+
+/**
+ * 封装各种生成唯一性ID算法的工具类.
+ * @author ThinkGem
+ * @version 2013-01-15
+ */
+
+public class IdGen {
+
+	private static SecureRandom random = new SecureRandom();
+	
+	/**
+	 * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
+	 */
+	public static String uuid() {
+		return UUID.randomUUID().toString().replaceAll("-", "");
+	}
+	
+	/**
+	 * 使用SecureRandom随机生成Long. 
+	 */
+	public static long randomLong() {
+		return Math.abs(random.nextLong());
+	}
+
+	/**
+	 * 基于Base62编码的SecureRandom随机生成bytes.
+	 */
+	public static String randomBase62(int length) {
+		byte[] randomBytes = new byte[length];
+		random.nextBytes(randomBytes);
+		return Encodes.encodeBase62(randomBytes);
+	}
+}

+ 12 - 0
zen-common/src/main/kotlin/com/gxzc/zen/persistence/ZenBaseDao.kt

@@ -0,0 +1,12 @@
+package com.gxzc.zen.persistence
+
+import com.baomidou.mybatisplus.mapper.BaseMapper
+import org.apache.ibatis.annotations.Param
+
+/**
+ * Created by mgr on 2018/1/23.
+ */
+interface ZenBaseDao<T>: BaseMapper<T> {
+    fun finds(@Param("cm") params:Map<String, Any?>): List<Long>
+    fun findList(@Param("cm") params:Map<String, Any?>): List<T>
+}

+ 29 - 0
zen-common/src/main/kotlin/com/gxzc/zen/persistence/ZenBaseModel.kt

@@ -0,0 +1,29 @@
+package com.gxzc.zen.persistence
+
+import com.baomidou.mybatisplus.annotations.TableField
+import com.baomidou.mybatisplus.annotations.TableId
+import com.baomidou.mybatisplus.enums.IdType
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
+import java.io.Serializable
+import java.util.*
+
+/**
+ * Created by mgr on 2018/1/23.
+ */
+abstract class ZenBaseModel: Serializable {
+    @JsonSerialize(using = ToStringSerializer::class)
+    @TableId(type = IdType.ID_WORKER)
+    var id:Long?=null
+    var createBy:String?=null
+    var createTime: Date?=null
+    var updateBy:String?=null
+    var updateTime: Date?=null
+    var remark:String?=null
+    var enable:Int?=null
+
+    @TableField(exist = false)
+    var map:Map<String,Any?>?=null
+
+    open fun preHandle(){}
+}

+ 92 - 0
zen-common/src/main/kotlin/com/gxzc/zen/persistence/ZenBaseService.kt

@@ -0,0 +1,92 @@
+package com.gxzc.zen.persistence
+
+import com.baomidou.kisso.SSOHelper
+import com.baomidou.kisso.security.token.SSOToken
+import com.baomidou.mybatisplus.plugins.Page
+import com.baomidou.mybatisplus.service.IService
+import com.gxzc.zen.plug.IdGen
+import org.apache.commons.lang3.StringUtils
+import org.springframework.beans.factory.annotation.Autowired
+import java.util.*
+import javax.servlet.http.HttpServletRequest
+
+/**
+ * Created by mgr on 2018/1/23.
+ */
+abstract class ZenBaseService<T: ZenBaseModel,D:ZenBaseDao<T>> {
+
+    @Autowired
+    protected val dao:D?=null
+
+    fun finds(params:Map<String, Any?>): List<Long>?{
+        return dao?.finds(params)
+    }
+    fun findList(params:Map<String, Any?>): List<T>?{
+        return dao?.findList(params)
+    }
+
+    fun findOne(params:Map<String, Any?>):T?{
+        val list=findList(params)
+        if(list!!.size>0)
+            return list.get(0)
+        return null
+    }
+
+    fun findID(id:String?):T?{
+        if(StringUtils.isBlank(id))return null
+        return dao?.selectById(id)
+//        return findOne(mapOf("id" to id))
+    }
+    fun findIDNum(idnum:Long?):T?{
+        if(idnum==null)return null
+        return findOne(mapOf("idnum" to idnum))
+    }
+
+    fun findPage(params: Map<String, Any?>): Page<T> {
+        val page=getPage(params)
+        val list=findList(params)
+        page.setRecords(list).setTotal(list!!.size)
+        return page
+    }
+
+    fun save(entity:T?):Int?{
+        return save(entity,null)
+    }
+    fun save(entity:T?,req: HttpServletRequest):Int?{
+        val token= SSOHelper.attrToken<SSOToken>(req)
+        return save(entity,token?.id)
+    }
+    fun save(entity:T?,ren:String?):Int?{
+        entity?.preHandle()
+        if(entity?.id==null||entity.id!!<=0) {
+            entity?.createBy=ren
+            entity?.createTime= Date()
+            return dao?.insert(entity) ?: -1
+        }else {
+            entity.updateBy=ren
+            entity.updateTime= Date()
+            return dao?.updateById(entity) ?: -1
+        }
+    }
+
+
+    /** 分页查询  */
+    fun getPage(params: Map<String, Any?>): Page<T> {
+        var current = 1
+        var size = 10
+        try {
+            if (params.containsKey("pageNum"))
+                current = params["pageNum"] as Int
+            if (params.containsKey("pageSize"))
+                size = params["pageSize"] as Int
+        }catch (e:Exception) { }
+        if (size < 0) {
+            val page = Page<T>()
+            page.isAsc = false
+            return page
+        }
+        val page = Page<T>(current, size)
+        page.isAsc = false
+        return page
+    }
+}