Переглянути джерело

搭建浦北-党建扶贫系统

lishuwen79 6 роки тому
коміт
595141a965
100 змінених файлів з 7037 додано та 0 видалено
  1. 119 0
      pom.xml
  2. 143 0
      src/main/java/com/lsw/Application.java
  3. 157 0
      src/main/java/com/lsw/base/BaseController.java
  4. 8 0
      src/main/java/com/lsw/base/BaseModel.java
  5. 73 0
      src/main/java/com/lsw/base/BaseValidator.java
  6. 58 0
      src/main/java/com/lsw/commons/generator/CodeGenerator.java
  7. 453 0
      src/main/java/com/lsw/commons/utils/CommonUtils.java
  8. 49 0
      src/main/java/com/lsw/commons/utils/Constant.java
  9. 65 0
      src/main/java/com/lsw/commons/utils/DruidKit.java
  10. 78 0
      src/main/java/com/lsw/commons/utils/EmailKit.java
  11. 30 0
      src/main/java/com/lsw/commons/utils/Exceptions.java
  12. 31 0
      src/main/java/com/lsw/commons/utils/FileEntity.java
  13. 161 0
      src/main/java/com/lsw/commons/utils/FileUtil.java
  14. 63 0
      src/main/java/com/lsw/commons/utils/HttpServletRequestWrapper.java
  15. 260 0
      src/main/java/com/lsw/commons/utils/ImageKit.java
  16. 170 0
      src/main/java/com/lsw/commons/utils/ImageZipUtil.java
  17. 59 0
      src/main/java/com/lsw/commons/utils/IpUtil.java
  18. 38 0
      src/main/java/com/lsw/commons/utils/Message.java
  19. 58 0
      src/main/java/com/lsw/commons/utils/RuntimeUtil.java
  20. 191 0
      src/main/java/com/lsw/commons/utils/SQL.java
  21. 155 0
      src/main/java/com/lsw/commons/utils/SendMessage.java
  22. 335 0
      src/main/java/com/lsw/commons/utils/TimeUtil.java
  23. 94 0
      src/main/java/com/lsw/controller/admin/system/department/DepartmentController.java
  24. 57 0
      src/main/java/com/lsw/controller/admin/system/department/DepartmentService.java
  25. 14 0
      src/main/java/com/lsw/controller/admin/system/department/DepartmentValidator.java
  26. 151 0
      src/main/java/com/lsw/controller/admin/system/file/FileController.java
  27. 49 0
      src/main/java/com/lsw/controller/admin/system/file/FileValidator.java
  28. 136 0
      src/main/java/com/lsw/controller/admin/system/index/IndexController.java
  29. 67 0
      src/main/java/com/lsw/controller/admin/system/index/IndexService.java
  30. 179 0
      src/main/java/com/lsw/controller/admin/system/letter/LetterController.java
  31. 87 0
      src/main/java/com/lsw/controller/admin/system/letter/LetterService.java
  32. 21 0
      src/main/java/com/lsw/controller/admin/system/letter/LetterValidator.java
  33. 50 0
      src/main/java/com/lsw/controller/admin/system/log/login/LlogController.java
  34. 53 0
      src/main/java/com/lsw/controller/admin/system/log/login/LlogService.java
  35. 52 0
      src/main/java/com/lsw/controller/admin/system/log/operation/OlogController.java
  36. 45 0
      src/main/java/com/lsw/controller/admin/system/log/operation/OlogService.java
  37. 125 0
      src/main/java/com/lsw/controller/admin/system/menu/MenuController.java
  38. 141 0
      src/main/java/com/lsw/controller/admin/system/menu/MenuService.java
  39. 14 0
      src/main/java/com/lsw/controller/admin/system/menu/MenuValidator.java
  40. 5 0
      src/main/java/com/lsw/controller/admin/system/package-info.java
  41. 151 0
      src/main/java/com/lsw/controller/admin/system/role/RoleController.java
  42. 58 0
      src/main/java/com/lsw/controller/admin/system/role/RoleService.java
  43. 15 0
      src/main/java/com/lsw/controller/admin/system/role/RoleValidator.java
  44. 67 0
      src/main/java/com/lsw/controller/admin/system/upload/UploadController.java
  45. 169 0
      src/main/java/com/lsw/controller/admin/system/user/UserController.java
  46. 88 0
      src/main/java/com/lsw/controller/admin/system/user/UserService.java
  47. 43 0
      src/main/java/com/lsw/controller/admin/system/user/UserValidator.java
  48. 82 0
      src/main/java/com/lsw/controller/admin/work/apply/ApplyController.java
  49. 79 0
      src/main/java/com/lsw/controller/admin/work/constant/ConstantController.java
  50. 5 0
      src/main/java/com/lsw/controller/admin/work/package-info.java
  51. 119 0
      src/main/java/com/lsw/controller/admin/work/process/ProcessController.java
  52. 92 0
      src/main/java/com/lsw/controller/front/ApplyController.java
  53. 53 0
      src/main/java/com/lsw/controller/front/ShareController.java
  54. 13 0
      src/main/java/com/lsw/controller/front/ShareValidator.java
  55. 23 0
      src/main/java/com/lsw/controller/front/user/AppUserController.java
  56. 71 0
      src/main/java/com/lsw/controller/front/user/AppUserService.java
  57. 19 0
      src/main/java/com/lsw/controller/front/user/AppUserValidator.java
  58. 25 0
      src/main/java/com/lsw/handler/ForbidHandler.java
  59. 25 0
      src/main/java/com/lsw/handler/StaticHandler.java
  60. 27 0
      src/main/java/com/lsw/handler/XssHandler.java
  61. 22 0
      src/main/java/com/lsw/interceptor/AccessAllowInterceptor.java
  62. 25 0
      src/main/java/com/lsw/interceptor/GlobalExceptionInterceptor.java
  63. 24 0
      src/main/java/com/lsw/interceptor/LogInterceptor.java
  64. 36 0
      src/main/java/com/lsw/interceptor/RoleMenuInterceptor.java
  65. 26 0
      src/main/java/com/lsw/interceptor/TokenInterceptor.java
  66. 63 0
      src/main/java/com/lsw/model/Apply.java
  67. 29 0
      src/main/java/com/lsw/model/Constant.java
  68. 11 0
      src/main/java/com/lsw/model/Department.java
  69. 48 0
      src/main/java/com/lsw/model/File.java
  70. 11 0
      src/main/java/com/lsw/model/Letter.java
  71. 11 0
      src/main/java/com/lsw/model/LetterUser.java
  72. 11 0
      src/main/java/com/lsw/model/LoginLog.java
  73. 11 0
      src/main/java/com/lsw/model/Menu.java
  74. 11 0
      src/main/java/com/lsw/model/MenuRole.java
  75. 11 0
      src/main/java/com/lsw/model/OperationLog.java
  76. 26 0
      src/main/java/com/lsw/model/Process.java
  77. 11 0
      src/main/java/com/lsw/model/Role.java
  78. 11 0
      src/main/java/com/lsw/model/Token.java
  79. 11 0
      src/main/java/com/lsw/model/User.java
  80. 11 0
      src/main/java/com/lsw/model/UserRole.java
  81. 36 0
      src/main/java/com/lsw/model/_MappingKit.java
  82. 84 0
      src/main/java/com/lsw/model/base/BaseApply.java
  83. 44 0
      src/main/java/com/lsw/model/base/BaseConstant.java
  84. 68 0
      src/main/java/com/lsw/model/base/BaseDepartment.java
  85. 156 0
      src/main/java/com/lsw/model/base/BaseFile.java
  86. 92 0
      src/main/java/com/lsw/model/base/BaseLetter.java
  87. 52 0
      src/main/java/com/lsw/model/base/BaseLetterUser.java
  88. 68 0
      src/main/java/com/lsw/model/base/BaseLoginLog.java
  89. 92 0
      src/main/java/com/lsw/model/base/BaseMenu.java
  90. 36 0
      src/main/java/com/lsw/model/base/BaseMenuRole.java
  91. 52 0
      src/main/java/com/lsw/model/base/BaseOperationLog.java
  92. 76 0
      src/main/java/com/lsw/model/base/BaseProcess.java
  93. 52 0
      src/main/java/com/lsw/model/base/BaseRole.java
  94. 36 0
      src/main/java/com/lsw/model/base/BaseToken.java
  95. 100 0
      src/main/java/com/lsw/model/base/BaseUser.java
  96. 36 0
      src/main/java/com/lsw/model/base/BaseUserRole.java
  97. 45 0
      src/main/java/com/lsw/route/AdminRoute.java
  98. 18 0
      src/main/java/com/lsw/route/FrontRoute.java
  99. 122 0
      src/main/java/com/lsw/shiro/ShiroDbRealm.java
  100. 34 0
      src/main/java/com/lsw/shiro/ext/AbstractAuthzHandler.java

+ 119 - 0
pom.xml

@@ -0,0 +1,119 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>djfp</groupId>
+    <artifactId>djfp</artifactId>
+    <packaging>war</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>djfp</name>
+    <url>http://maven.apache.org</url>
+    <properties>
+        <jfinal.version>3.2</jfinal.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
+    </properties>
+    <dependencies>
+        <!--jfinal -->
+        <dependency>
+            <groupId>com.jfinal</groupId>
+            <artifactId>jfinal</artifactId>
+            <version>${jfinal.version}</version>
+        </dependency>
+        <!--jfinal微信 -->
+        <dependency>
+            <groupId>com.jfinal</groupId>
+            <artifactId>jfinal-weixin</artifactId>
+            <version>1.9</version>
+        </dependency>
+        <!-- jetty -->
+        <dependency>
+            <groupId>com.jfinal</groupId>
+            <artifactId>jetty-server</artifactId>
+            <version>8.1.8</version>
+            <scope>compile</scope>
+           <!-- <scope>test</scope>-->
+        </dependency>
+        <!--单元测试-->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+            <scope>test</scope>
+        </dependency>
+        <!--druid连接池 -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.0.18</version>
+        </dependency>
+        <!--mysql驱动 -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.29</version>
+        </dependency>
+        <!-- 日志 -->
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.17</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.7.21</version>
+        </dependency>
+        <!-- 上传文件依赖 -->
+        <dependency>
+            <groupId>com.jfinal</groupId>
+            <artifactId>cos</artifactId>
+            <version>26Dec2008</version>
+        </dependency>
+        <!-- 缓存依赖 -->
+        <dependency>
+            <groupId>net.sf.ehcache</groupId>
+            <artifactId>ehcache-core</artifactId>
+            <version>2.6.6</version>
+        </dependency>
+        <!-- fastjson -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.6</version>
+        </dependency>
+        <!-- shiro权限 -->
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-all</artifactId>
+            <version>1.2.6</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <!--发送邮件-->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-email</artifactId>
+            <version>1.2</version>
+        </dependency>
+        <!--定时任务-->
+        <dependency>
+            <groupId>it.sauronsoftware.cron4j</groupId>
+            <artifactId>cron4j</artifactId>
+            <version>2.2.5</version>
+        </dependency>
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>RELEASE</version>
+        </dependency>
+    </dependencies>
+    <build>
+        <finalName>djfp</finalName>
+        <plugins>
+        </plugins>
+    </build>
+    <description>浦北-党建扶贫系统</description>
+</project>

+ 143 - 0
src/main/java/com/lsw/Application.java

@@ -0,0 +1,143 @@
+package com.lsw;
+
+import com.alibaba.druid.filter.stat.StatFilter;
+import com.alibaba.druid.wall.WallFilter;
+import com.jfinal.config.*;
+import com.jfinal.core.JFinal;
+import com.jfinal.ext.handler.ContextPathHandler;
+import com.jfinal.json.FastJsonFactory;
+import com.jfinal.json.MixedJsonFactory;
+import com.jfinal.kit.PathKit;
+import com.jfinal.kit.PropKit;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.cron4j.Cron4jPlugin;
+import com.jfinal.plugin.druid.DruidPlugin;
+import com.jfinal.plugin.ehcache.EhCachePlugin;
+import com.jfinal.template.Engine;
+import com.jfinal.weixin.sdk.api.ApiConfig;
+import com.jfinal.weixin.sdk.api.ApiConfigKit;
+import com.lsw.commons.utils.DruidKit;
+import com.lsw.interceptor.AccessAllowInterceptor;
+import com.lsw.model._MappingKit;
+import com.lsw.route.AdminRoute;
+import com.lsw.route.FrontRoute;
+import com.lsw.shiro.ext.ShiroInterceptor;
+import com.lsw.shiro.ext.ShiroPlugin;
+import com.lsw.shiro.tag.ShiroTag;
+
+/**
+ * @author 李书文
+ * @description 应用程序入口
+ * @time 20161022
+ */
+public class Application extends JFinalConfig {
+    Routes routes;
+    @Override
+    public void configConstant(Constants me) {
+        // 加载少量必要配置,随后可用PropKit.get(...)获取值
+        PropKit.use("conf/jdbc_config.properties");
+        me.setError401View("/WEB-INF/view/error/401.html");
+        me.setError404View("/WEB-INF/view/error/404.html");
+        me.setError500View("/WEB-INF/view/error/500.html");
+        me.setDevMode(PropKit.getBoolean("devMode", false));
+        me.setMaxPostSize(1024 * 1024 * 1000 * 10);
+        me.setJsonDatePattern("yyyy-MM-dd HH:mm");
+    }
+
+    @Override
+    public void configRoute(Routes me) {
+        this.routes = me;
+        me.add(new AdminRoute()); // 后端路由
+        me.add(new FrontRoute()); // 前端路由
+    }
+
+    public static DruidPlugin createDruidPlugin() {
+        return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
+    }
+
+    @Override
+    public void configPlugin(Plugins me) {
+        DruidPlugin dp = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
+        dp.addFilter(new StatFilter());
+        WallFilter wall = new WallFilter();   // 加强数据库安全
+        wall.setDbType("mysql");
+        dp.addFilter(wall);
+        dp.setMaxWait(300000);
+        dp.addFilter(new StatFilter()); // 添加 StatFilter才会有统计数据
+        me.add(dp);
+
+        // 配置ActiveRecord插件
+        ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
+        arp.setShowSql(true);
+        arp.setBaseSqlTemplatePath(PathKit.getRootClassPath() + "/sql/");
+        arp.addSqlTemplate("include.sql");
+        arp.getSqlKit().getEngine().addSharedObject("str", new StrKit());
+        _MappingKit.mapping(arp);
+        me.add(arp);
+
+        // 配置ShiroPlugin插件
+        ShiroPlugin shiroPlugin = new ShiroPlugin();
+        shiroPlugin.setLoginUrl("/admin/login");//登陆url:未验证成功跳转
+        shiroPlugin.setUnauthorizedUrl("/admin/error");//授权url:未授权成功自动跳转
+        me.add(shiroPlugin);
+
+        // 配置EhCachePlugin插件
+        me.add(new EhCachePlugin());
+
+        // 配置定时任务插件
+        Cron4jPlugin cron4 = new Cron4jPlugin("task.properties");
+        me.add(cron4);
+    }
+
+    @Override
+    public void configInterceptor(Interceptors me) {
+        me.add(new ShiroInterceptor());
+        me.add(new AccessAllowInterceptor());
+        //全局异常处理
+        // me.addGlobalActionInterceptor(new GlobalExceptionInterceptor());
+    }
+
+    @Override
+    public void configHandler(Handlers me) {
+        me.add(DruidKit.getDruidStatViewHandler());
+        me.add(new ContextPathHandler("path"));
+    }
+
+    @Override
+    public void afterJFinalStart() {
+        // 配置微信 API 相关参数
+        ApiConfig ac = new ApiConfig();
+        ac.setAppId(PropKit.get("appId"));
+        ac.setAppSecret(PropKit.get("appSecret"));
+        ac.setEncryptMessage(PropKit.getBoolean("encryptMessage", false));
+        ac.setEncodingAesKey(PropKit.get("encodingAesKey", "setting it in config file"));
+        ApiConfigKit.putApiConfig(ac);
+        welcome();
+    }
+
+    private void welcome() {
+        System.out.println("系统启动完成 ");
+    }
+
+    public static void main(String[] args) {
+        JFinal.start("src/main/webapp", 7979, "/");
+    }
+
+    @Override
+    public void configEngine(Engine me) {
+        /********************************后端全局模板*************************************/
+        //头部
+        me.addSharedFunction("/WEB-INF/view/admin/common/header.html");
+        //js集合
+        me.addSharedFunction("/WEB-INF/view/admin/common/js_include.html");
+        //表单操作按钮
+        me.addSharedFunction("/WEB-INF/view/admin/common/op_button.html");
+        //角色操作按钮
+        me.addSharedFunction("/WEB-INF/view/admin/common/role_menu.html");
+        //shiro标签
+        me.addSharedObject("shiro", new ShiroTag());
+        me.addSharedObject("host", PropKit.get("ip"));
+    }
+
+}

+ 157 - 0
src/main/java/com/lsw/base/BaseController.java

@@ -0,0 +1,157 @@
+package com.lsw.base;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.jfinal.json.Json;
+import com.jfinal.kit.HttpKit;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.weixin.sdk.jfinal.ApiController;
+import com.lsw.commons.utils.TimeUtil;
+
+public class BaseController extends ApiController {
+    /**
+     * 获取分页码
+     *
+     * @return
+     */
+    protected int getPage() {
+        return getParaToInt("page", 1);
+    }
+
+    /**
+     * 获取分页条数
+     *
+     * @return
+     */
+    protected int getRows() {
+        return getParaToInt("rows", 10);
+    }
+
+    /**
+     * 排序方式
+     *
+     * @return
+     */
+    protected String getSord() {
+        String sord = getPara("sord", "desc");
+        return sord;
+    }
+
+    /**
+     * 排序字段
+     *
+     * @return
+     */
+    protected String getSidx() {
+        String sidx = getPara("sidx", "id");
+        return sidx;
+    }
+
+    /**
+     * 封装jqgrid分页数据
+     *
+     * @param pageInfo
+     * @return
+     */
+    protected Map<String, Object> getPage(Page pageInfo) {
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("rows", pageInfo.getList());
+        map.put("total", pageInfo.getTotalPage());
+        map.put("records", pageInfo.getTotalRow());
+        map.put("page", pageInfo.getPageNumber());
+        return map;
+    }
+
+    /**
+     * 获取最小查询时间
+     *
+     * @return
+     */
+    protected String getMinTime() {
+        String minTime = getPara("min", "");
+        return minTime;
+    }
+
+    /**
+     * 获取最大查询时间
+     *
+     * @return
+     */
+    protected String getMaxTime() {
+        String maxTime = getPara("max", TimeUtil.getDay());
+        return maxTime+" 23:59";
+
+    }
+
+    /**
+     * 将post的json结构体转成Bean
+     *
+     * @param clazz 类
+     * @return Bean
+     */
+    public <T> T getJsonReqBody(Class<T> clazz) {
+        String jsonString = getReqBody();
+        if (StrKit.isBlank(jsonString)) {
+            return null;
+        }
+        return Json.getJson().parse(jsonString, clazz);
+    }
+
+    /**
+     * 获取post的结构体
+     *
+     * @return json or xml字符串
+     */
+    public String getReqBody() {
+        return HttpKit.readData(getRequest());
+    }
+
+    /**
+     * 成功并携带数据
+     *
+     * @param data
+     */
+    public void renderSuccess(Object data) {
+        Record record = new Record();
+        record.set("result", true);
+        record.set("data", data);
+        renderJson(record);
+    }
+    /**
+     * 成功并自定义提示消息
+     *
+     * @param string
+     */
+    public void renderSuccess(String string) {
+        Record record = new Record();
+        record.set("result", true);
+        record.set("msg", string);
+        renderJson(record);
+    }
+
+    /**
+     * 成功
+     *
+     * @param
+     */
+    public void renderSuccess() {
+        Record record = new Record();
+        record.set("result", true);
+        renderJson(record);
+    }
+
+    /**
+     * 失败信息
+     *
+     * @param string
+     */
+    public void renderError(String string) {
+        Record record = new Record();
+        record.set("result", false);
+        record.set("msg", string);
+        renderJson(record);
+    }
+}

+ 8 - 0
src/main/java/com/lsw/base/BaseModel.java

@@ -0,0 +1,8 @@
+package com.lsw.base;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class BaseModel<M extends Model<M>> extends Model<M> {
+	private static final long serialVersionUID = -5718606395714034111L;
+
+}

+ 73 - 0
src/main/java/com/lsw/base/BaseValidator.java

@@ -0,0 +1,73 @@
+package com.lsw.base;
+
+import com.jfinal.core.Controller;
+import com.jfinal.validate.Validator;
+
+/**
+ * 
+ * @author 李书文
+ * @description 基础校验器
+ * @time 20161028
+ */
+public abstract class BaseValidator extends Validator {
+
+
+	//6-20未用户名
+	public static final String USER_NAME = "^[A-Za-z0-9]{6,20}$";
+	//密码必须是数字和字母
+	public static final String USER_PASSWORD = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
+	//手机号
+	public static final String PHONE = "^1[34578]\\d{9}$";
+	//身份证校验,初级校验,具体规则有一套算法
+	public static final String ID_CARD = "^\\d{15}$|^\\d{17}([0-9]|X)$";
+
+	{this.setShortCircuit(true);}
+
+	/**
+	 * 输入6-20位的字母或数字
+	 * @param field
+	 * @param errorKey
+	 * @param errorMsg
+	 */
+	protected void validateAccount(String field,String errorKey,String errorMsg){
+		validateRegex(field, USER_NAME, false, errorKey, errorMsg);
+	}
+
+	/**
+	 * 验证手机号格式
+	 * @param field
+	 * @param errorKey
+	 * @param errorMsg
+	 */
+	protected void validatePhone(String field,String errorKey,String errorMsg){
+		validateRegex(field, PHONE, false, errorKey, errorMsg);
+	}
+
+	/**
+	 * 验证身份证号码
+	 * @param field
+	 * @param errorKey
+	 * @param errorMsg
+	 */
+	protected void validateIdCard(String field,String errorKey,String errorMsg){
+		validateRegex(field, ID_CARD, false, errorKey, errorMsg);
+	}
+
+	/**
+	 * 密码必须是数字和字母
+	 * @param field
+	 * @param errorKey
+	 * @param errorMsg
+	 */
+	protected void validatePassword(String field,String errorKey,String errorMsg){
+		validateRegex(field, ID_CARD, false, errorKey, errorMsg);
+	}
+
+
+
+	@Override
+	protected void handleError(Controller c) {
+		c.setAttr("result", false);
+		c.renderJson(new String[] { "result", "msg" });
+	}
+}

+ 58 - 0
src/main/java/com/lsw/commons/generator/CodeGenerator.java

@@ -0,0 +1,58 @@
+package com.lsw.commons.generator;
+
+import javax.sql.DataSource;
+
+import com.jfinal.kit.PathKit;
+import com.jfinal.kit.PropKit;
+import com.jfinal.plugin.activerecord.generator.Generator;
+import com.jfinal.plugin.druid.DruidPlugin;
+import com.lsw.Application;
+
+/**
+ * 在数据库表有任何变动时,运行一下 main 方法,极速响应变化进行代码重构
+ */
+public class CodeGenerator {
+    //是否是手动代码生成
+	public static boolean CodeGeneration=false;
+	static  String baseModelOutputDir;
+	public static DataSource getDataSource() {
+		PropKit.use("conf/jdbc_config.properties");
+		DruidPlugin druidPlugin = Application.createDruidPlugin();
+		druidPlugin.start();
+		return druidPlugin.getDataSource();
+	}
+
+	public static void main(String[] args) {
+		// base model 所使用的包名
+		String baseModelPackageName = "com.lsw.model.base";
+		// base model 文件保存路径
+		if(CodeGeneration){
+			baseModelOutputDir =System.getProperty("user.dir")+ "/src/main/java/com/lsw/model/base";
+		}else{
+			baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/lsw/model/base";
+		}
+
+		// model 所使用的包名 (MappingKit 默认使用的包名)
+		String modelPackageName = "com.lsw.model";
+		// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
+		String modelOutputDir = baseModelOutputDir + "/..";
+
+		// 创建生成器
+		Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir,
+				modelPackageName, modelOutputDir);
+
+		// 添加不需要生成的表名
+		 gernerator.addExcludedTable("tb_session");
+		// 设置是否在 Model 中生成 dao 对象
+		gernerator.setGenerateDaoInModel(true);
+		// 设置是否生成链式 setter 方法
+		//gernerator.setGenerateChainSetter(true);
+		// 设置是否生成字典文件
+		gernerator.setGenerateDataDictionary(false);
+		// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为
+		// "User"而非 OscUser
+		gernerator.setRemovedTableNamePrefixes("sys_","tb_");
+		// 生成
+		gernerator.generate();
+	}
+}

+ 453 - 0
src/main/java/com/lsw/commons/utils/CommonUtils.java

@@ -0,0 +1,453 @@
+
+package com.lsw.commons.utils;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Random;
+import java.util.UUID;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.imageio.ImageIO;
+
+/**
+ * @author 李书文
+ * @description 常用的工具类
+ * @time 20161028
+ */
+public class CommonUtils {
+
+    public static String createUUID() {
+        return UUID.randomUUID().toString().replaceAll("-", "");
+    }
+
+    public static String getMACAddress(String ip) {
+        String str = "";
+        String macAddress = "";
+        try {
+            Process p = Runtime.getRuntime().exec("nbtstat -A " + ip);
+            InputStreamReader ir = new InputStreamReader(p.getInputStream());
+            LineNumberReader input = new LineNumberReader(ir);
+            for (int i = 1; i < 100; i++) {
+                str = input.readLine();
+                if (str != null) {
+                    if (str.indexOf("MAC Address") > 1) {
+                        macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
+                        break;
+                    }
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace(System.out);
+        }
+        return macAddress;
+    }
+
+    /**
+     * 得到文件的后缀名<br/>
+     * System.out.println(getFileSubString("yulong.jpg"));>>>.jpg
+     *
+     * @param fileName
+     * @return
+     */
+    public static String getFileSubString(String fileName) {
+        if (fileName != null && fileName.indexOf(".") != -1) {
+            return fileName.substring(fileName.indexOf("."));
+        }
+        return "";
+    }
+
+    /**
+     * 判断字符串是否包含内容
+     */
+    public static boolean isNotEmpty(String str) {
+        return str != null && !str.trim().equals("");
+    }
+
+    /**
+     * 判断数字是否大于零
+     */
+    public static boolean isGtZero(Long ls) {
+        return ls != null && ls > 0;
+    }
+
+    /**
+     * 判断数字是否大于零
+     */
+    public static boolean isGtZero(Integer ls) {
+        return ls != null && ls > 0;
+    }
+
+    /**
+     * 随机count位数字字符串<br/>
+     * 可以用来生成代金券号码和密码
+     *
+     * @param count 随机多少位
+     */
+    public static String getRandomString(int count) {
+        if (count > 0) {
+            StringBuilder buf = new StringBuilder();
+            Random rd = new Random();
+            for (int i = 0; i < count; i++) {
+                buf.append(rd.nextInt(10));
+            }
+            return buf.toString();
+        } else {
+            return "";
+        }
+
+    }
+
+    /**
+     * 隐藏字符串中部分敏感信息
+     *
+     * @param tg    目标字符串
+     * @param start 开始索引
+     * @param end   结束索引
+     * @return
+     */
+    public static String hidepartChar(String tg, int start, int end) {
+        return new StringBuffer(tg).replace(start, end, "**").toString();
+    }
+
+    /**
+     * 判断字符在字符串中出现的次数
+     *
+     * @param tg
+     * @param fg
+     * @return
+     */
+    public static Integer getCountInStr(String tg, char fg) {
+        if (isNotEmpty(tg)) {
+            int i = 0;
+            if (isNotEmpty(tg)) {
+                char ch[] = tg.toCharArray();
+                for (char c : ch) {
+                    if (c == fg) {
+                        i++;
+                    }
+                }
+            }
+            return i;
+        }
+        return 0;
+    }
+
+    /***
+     * 对象数组转换成对象集合
+     *
+     * @param <T>
+     * @param ts
+     * @return
+     */
+    public static <T> List<T> getList(T... ts) {
+        return Arrays.asList(ts);
+    }
+
+    /**
+     * 得到long类型集合 如果遇到不能转换为long类型的字符串跳过 返回能转换为long类型的long类型集合
+     *
+     * @param strings
+     * @return
+     */
+    public static List<Long> getListByStrs(String... strings) {
+        List<Long> list = new ArrayList<Long>();
+        if (strings != null) {
+            for (String s : strings) {
+                try {
+                    if (isNotEmpty(s)) {
+                        list.add(Long.valueOf(s));
+                    }
+                } catch (NumberFormatException e) {
+                }
+            }
+        }
+        return list;
+    }
+
+    /**
+     * 把首字母变成大写
+     *
+     * @param str要转换的字符串
+     * @return
+     */
+    public static String toUpcaseFist(String str) {
+        if (str != null && !str.trim().equals("")) {
+            if (str.length() == 1) {
+                return str.toUpperCase();
+            } else {
+                return str.substring(0, 1).toUpperCase() + str.substring(1);
+            }
+        } else {
+            return "";
+        }
+
+    }
+
+    /**
+     * 根据键值对得到map<String,Object>对象
+     *
+     * @param ag
+     * @return
+     */
+    public static LinkedHashMap<String, Object> getMap(Object... ag) {
+        LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
+        if (ag != null && ag.length > 0 && ag.length % 2 == 0) {
+            int i = 0;
+            for (@SuppressWarnings("unused")
+                    Object o : ag) {
+                mp.put(String.valueOf(ag[i]), ag[++i]);
+                i++;
+                if (i == ag.length) {
+                    break;
+                }
+
+            }
+        }
+        return mp;
+    }
+
+    /**
+     * 根据键值对得到map<String,String>对象
+     *
+     * @param ag
+     * @return
+     */
+    public static LinkedHashMap<String, String> getStrValueMap(String... ag) {
+        LinkedHashMap<String, String> mp = new LinkedHashMap<String, String>();
+        if (ag != null && ag.length > 0 && ag.length % 2 == 0) {
+            int i = 0;
+            for (@SuppressWarnings("unused")
+                    String o : ag) {
+                mp.put(ag[i], ag[++i]);
+                i++;
+                if (i == ag.length) {
+                    break;
+                }
+
+            }
+        }
+        return mp;
+    }
+
+    /**
+     * 动态图像转换成静态图片
+     *
+     * @param file图片文件
+     */
+    public static void convertImageToStatic(File file) {
+        if (file != null) {
+            try {
+                BufferedImage bufferedimage = ImageIO.read(file);
+                if (bufferedimage != null) {
+                    ImageIO.write(bufferedimage, "gif", file);// 1131.gif是静态的
+                }
+            } catch (IOException e) {
+            }
+        }
+    }
+
+    /**
+     * 判断是否为数字
+     *
+     * @param tg
+     * @return
+     */
+    public static Boolean isNumber(String tg) {
+        if (isNotEmpty(tg)) {
+            try {
+                Double.valueOf(tg);
+                return true;
+            } catch (NumberFormatException e) {
+            }
+        }
+        return false;
+    }
+
+    /**
+     * 处理浮点数相加运算
+     *
+     * @param v
+     * @param v2
+     * @return
+     */
+    public static Double floatAdd(Double v, Double v2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(v));
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
+        return b1.add(b2).doubleValue();
+    }
+
+    /**
+     * 处理浮点数相减运算
+     *
+     * @param v  被减数
+     * @param v2 减数
+     * @return
+     */
+    public static Double floatSubtract(Double v, Double v2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(v));
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
+        return b1.subtract(b2).doubleValue();
+    }
+
+    /**
+     * 处理浮点数相除
+     *
+     * @param v
+     * @param v2
+     * @return
+     */
+    public static Double floatDiv(Double v, Double v2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(v));
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
+        return b1.divide(b2).doubleValue();
+    }
+
+    /**
+     * 处理浮点数相乘
+     *
+     * @param v
+     * @param v2
+     * @return
+     */
+    public static Double floatMulply(Double v, Double v2) {
+        BigDecimal b1 = new BigDecimal(Double.toString(v));
+        BigDecimal b2 = new BigDecimal(Double.toString(v2));
+        return b1.multiply(b2).doubleValue();
+    }
+
+    /**
+     * 判断集合是否不为空
+     *
+     * @param list
+     * @return
+     */
+    public static Boolean isNotEmpty(@SuppressWarnings("rawtypes") Collection list) {
+        return list != null && list.size() > 0;
+    }
+
+    /**
+     * 判断数组是否不为空
+     *
+     * @param arr
+     * @return
+     */
+    public static Boolean isNotEmptyArr(Object[] arr) {
+        return arr != null && arr.length > 0;
+    }
+
+    /******************* 华丽分割线 ****************************************************************/
+
+    /**
+     * 对页面显示内容进行编码
+     *
+     * @param str
+     * @return
+     */
+    public static String htmlEncoding(String str) {
+        StringBuffer bfu = new StringBuffer();
+        if (str != null) {
+            String s = "&#";
+            char[] cs = str.toCharArray();
+            for (char c : cs) {
+                int it = c;
+                bfu.append(s).append(it).append(";");
+            }
+        }
+        return bfu.toString();
+
+    }
+
+    /**
+     * 得到json数据格式
+     *
+     * @param flag     obj[key] key数组
+     * @param property name,age..对象属性数组
+     * @param values   yulong,22.对象属性对应的值
+     * @return
+     */
+    public static StringBuffer getJson(String[] flag, String[] property, List<String[]> values) {
+        StringBuffer buf = new StringBuffer();
+        if (flag != null && property != null && property.length > 0) {
+            if (values != null && values.size() > 0 && property.length == values.get(0).length
+                    && values.size() == flag.length) {
+                Iterator<String[]> ite = values.iterator();
+                buf.append("({");
+                for (int j = 0; j < flag.length; j++) {
+                    buf.append("\"").append(flag[j]).append("\"").append(":");
+                    String[] ss = ite.next();
+                    buf.append("{");
+                    for (int i = 0; i < property.length; i++) {
+                        buf.append(property[i]).append(":").append("\"").append(ss[i]).append("\"");
+                        if (property.length - 1 > i) {
+                            buf.append(",");
+                        }
+                    }
+                    buf.append("}");
+                    if (ite.hasNext()) {
+                        buf.append(",");
+                    }
+                }
+                buf.append("})");
+            }
+
+        }
+        return buf;
+    }
+
+    public static String autoDigest(String str, int size) {
+        String digest = str.replaceAll("<[^>]*>", "").replaceAll("\t|\r|", "").replace("\n", " ");
+        if (digest.length() > size) {
+            digest = digest.substring(0, size) + "  ...";
+        }
+        return digest;
+    }
+
+    // 将数字转化为大写
+    public static String numToUpper(int num) {
+        // String u[] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};    
+        String u[] = {"〇", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
+        char[] str = String.valueOf(num).toCharArray();
+        String rstr = "";
+        for (int i = 0; i < str.length; i++) {
+            rstr = rstr + u[Integer.parseInt(str[i] + "")];
+        }
+        return rstr;
+    }
+    public static String resolveToByteFromEmoji(String str) {
+        Pattern pattern = Pattern
+                .compile("[^(\u2E80-\u9FFF\\w\\s`~!@#\\$%\\^&\\*\\(\\)_+-?()——=\\[\\]{}\\|;。,、《》”:;“!……’:'\"<,>\\.?/\\\\*)]");
+        Matcher matcher = pattern.matcher(str);
+        StringBuffer sb2 = new StringBuffer();
+        while (matcher.find()) {
+            matcher.appendReplacement(sb2, resolveToByte(matcher.group(0)));
+        }
+        matcher.appendTail(sb2);
+        return sb2.toString();
+    }
+    private static String resolveToByte(String str) {
+        byte[] b = str.getBytes();
+        StringBuffer sb = new StringBuffer();
+        sb.append("<:");
+        for (int i = 0; i < b.length; i++) {
+            if (i < b.length - 1) {
+                sb.append(Byte.valueOf(b[i]).toString() + ",");
+            } else {
+                sb.append(Byte.valueOf(b[i]).toString());
+            }
+        }
+        sb.append(":>");
+        return sb.toString();
+    }
+}
+

+ 49 - 0
src/main/java/com/lsw/commons/utils/Constant.java

@@ -0,0 +1,49 @@
+package com.lsw.commons.utils;
+
+/**
+ * Created by lishuwen on 2017/6/28.
+ */
+public class Constant {
+	// 富文本最大上传图片大小
+	public static int maxPostSize = 1024 * 1024 * 20;
+	// 用户信息缓存
+	public static String userCache = "userCache";
+	// 角色资源菜单缓存
+	public static String menuRoleCache = "menuRoleListCache";
+	// url缓存
+	public static String urlCache = "urlCache";
+	// 验证码缓存5分钟
+	public static String code = "code";
+	// token缓存
+	public static String token = "token";
+	// 旅游与法
+	public static String travel = "travel";
+	// 旅游与法详情
+	public static String travel_detail = "travel_detail";
+	// 题库缓存
+	public static String exam = "exam";
+	// 法制宣传栏目缓存
+	public static String columns = "columns";
+	// 区县频道缓存
+	public static String districts = "districts";
+	// 区县频道详情缓存
+	public static String districts_detail = "districts_detail";
+	// 法制宣传缓存
+	public static String publicity = "publicity";
+	// 法制宣传详情缓存
+	public static String publicity_detail = "publicity_detail";
+	// 视频缓存
+	public static String video = "video";
+	// 寻找律师缓存
+	public static String lawyer = "lawyer";
+	// 律师详情缓存
+	public static String lawyer_detail = "lawyer_detail";
+	// 服务机构缓存
+	public static String organization = "organization";
+	// 服务机构详情缓存
+	public static String organization_detail = "organization_detail";
+	// 检查用户今天是否已经预约(一个用户一天只能预约一次)
+	public static String checkAppointment = "checkAppointment";
+	// 如果当天该用户第一次向律师咨询,通知该律师处理
+	public static String checkDayConsul = "checkDayConsul";
+}

+ 65 - 0
src/main/java/com/lsw/commons/utils/DruidKit.java

@@ -0,0 +1,65 @@
+/**
+ * 请勿将俱乐部专享资源复制给其他人,保护知识产权即是保护我们所在的行业,进而保护我们自己的利益
+ * 即便是公司的同事,也请尊重 JFinal 作者的努力与付出,不要复制给同事
+ *
+ * 如果你尚未加入俱乐部,请立即删除该项目,或者现在加入俱乐部:http://jfinal.com/club
+ *
+ * 俱乐部将提供 jfinal-club 项目文档与设计资源、专用 QQ 群,以及作者在俱乐部定期的分享与答疑,
+ * 价值远比仅仅拥有 jfinal club 项目源代码要大得多
+ *
+ * JFinal 俱乐部是五年以来首次寻求外部资源的尝试,以便于有资源创建更加
+ * 高品质的产品与服务,为大家带来更大的价值,所以请大家多多支持,不要将
+ * 首次的尝试扼杀在了摇篮之中
+ */
+
+package com.lsw.commons.utils;
+
+import com.jfinal.plugin.druid.DruidStatViewHandler;
+import com.jfinal.plugin.druid.IDruidStatViewAuth;
+import com.lsw.shiro.tag.ShiroTag;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 创建 DruidStatViewHandler 的工具类
+ *
+ * 可通过 "/assets/druid" 访问到 druid 提供的 sql 监控与统计功能
+ * 方便找到慢 sql,进而对慢 sql 进行优化
+ * 注意:这里的访问路径是下面代码中指定的,可以设置为任意路径
+ *
+ * 注意 druid 监控模块中使用的静态资源文件如 .html .css 被打包在了 druid 的jar 包之中
+ * 如果你的项目在前端有 nginx 代理过了这些静态资源,需要将这些资源解压出来并放到
+ * 正确的目录下面
+ *
+ * 具体到该配置中的 url 为 "/druid",那么相关静态资源需要解压到该目录之下
+ */
+public class DruidKit {
+
+    @RequiresPermissions("druid")
+	public static DruidStatViewHandler getDruidStatViewHandler() {
+		return  new DruidStatViewHandler("/druid", new IDruidStatViewAuth() {
+			public boolean isPermitted(HttpServletRequest request) {
+                if(new ShiroTag().hasPermission("druid")){
+                    return true;
+                }
+				return false;
+			}
+		});
+	}
+
+	public static String getCookie(HttpServletRequest request, String name) {
+		Cookie cookie = getCookieObject(request, name);
+		return cookie != null ? cookie.getValue() : null;
+	}
+
+	private static Cookie getCookieObject(HttpServletRequest request, String name) {
+		Cookie[] cookies = request.getCookies();
+		if (cookies != null)
+			for (Cookie cookie : cookies)
+				if (cookie.getName().equals(name))
+					return cookie;
+		return null;
+	}
+}

+ 78 - 0
src/main/java/com/lsw/commons/utils/EmailKit.java

@@ -0,0 +1,78 @@
+/**
+ * 请勿将俱乐部专享资源复制给其他人,保护知识产权即是保护我们所在的行业,进而保护我们自己的利益
+ * 即便是公司的同事,也请尊重 JFinal 作者的努力与付出,不要复制给同事
+ * <p>
+ * 如果你尚未加入俱乐部,请立即删除该项目,或者现在加入俱乐部:http://jfinal.com/club
+ * <p>
+ * 俱乐部将提供 jfinal-club 项目文档与设计资源、专用 QQ 群,以及作者在俱乐部定期的分享与答疑,
+ * 价值远比仅仅拥有 jfinal club 项目源代码要大得多
+ * <p>
+ * JFinal 俱乐部是五年以来首次寻求外部资源的尝试,以便于有资源创建更加
+ * 高品质的产品与服务,为大家带来更大的价值,所以请大家多多支持,不要将
+ * 首次的尝试扼杀在了摇篮之中
+ */
+
+package com.lsw.commons.utils;
+
+import com.jfinal.kit.PropKit;
+import com.jfinal.kit.StrKit;
+import com.jfinal.log.Log;
+import org.apache.commons.mail.EmailAttachment;
+import org.apache.commons.mail.HtmlEmail;
+
+import javax.mail.internet.MimeUtility;
+import java.io.File;
+
+/**
+ * 邮件发送工具类
+ */
+public class EmailKit {
+
+    private static final Log log = Log.getLog(EmailKit.class);
+
+    /**
+     * @param toEmail 收件人
+     * @param title   邮件标题
+     * @param content 邮件内容
+     * @param path    附件地址
+     * @return true
+     */
+    public static boolean sendEmail(String toEmail, String title, String content, String path) {
+        try {
+            HtmlEmail email = new HtmlEmail();
+            email.setAuthentication(PropKit.get("fromEmail"), PropKit.get("emailPass"));
+            email.setHostName(PropKit.get("emailServer"));
+            email.addTo(toEmail);
+            email.setFrom(PropKit.get("fromEmail"));
+            email.setSubject(title);
+            email.setCharset("utf-8");
+            email.setHtmlMsg(content);
+            //带附件
+            if (StrKit.notBlank(path)) {
+                EmailAttachment attachment = new EmailAttachment();
+                //附件的地址
+                attachment.setPath(path);
+                //附件名称
+                String name = new File(path).getName();
+                attachment.setName(MimeUtility.encodeText(name));
+                // 设定为附件
+                attachment.setDisposition(EmailAttachment.ATTACHMENT);
+                email.attach(attachment);
+            }
+            email.send();
+            return true;
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return false;
+        }
+    }
+
+    public static void main(String[] args) {
+    }
+}
+
+		
+	
+	
+
+

+ 30 - 0
src/main/java/com/lsw/commons/utils/Exceptions.java

@@ -0,0 +1,30 @@
+package com.lsw.commons.utils;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * 异常处理工具类,让异常不再杂乱无章
+ * @author L.cm
+ */
+public abstract class Exceptions {
+	/**
+	 * 将CheckedException转换为UncheckedException.
+	 */
+	public static RuntimeException unchecked(Throwable e) {
+		if (e instanceof RuntimeException) {
+			return (RuntimeException) e;
+		} else {
+			return new RuntimeException(e);
+		}
+	}
+	
+	/**
+	 * 将ErrorStack转化为String.
+	 */
+	public static String getStackTraceAsString(Throwable ex) {
+		StringWriter stringWriter = new StringWriter();
+		ex.printStackTrace(new PrintWriter(stringWriter));
+		return stringWriter.toString();
+	}
+}

+ 31 - 0
src/main/java/com/lsw/commons/utils/FileEntity.java

@@ -0,0 +1,31 @@
+package com.lsw.commons.utils;
+
+public class FileEntity  {
+	private String path;
+	private String fileName;
+
+	public FileEntity() {
+		super();
+	}
+
+	public FileEntity(String path, String fileName) {
+		this.path = path;
+		this.fileName = fileName;
+	}
+
+	public void setPath(String path) {
+		this.path = path;
+	}
+
+	public void setFileName(String fileName) {
+		this.fileName = fileName;
+	}
+
+	public String getPath() {
+		return path;
+	}
+
+	public String getFileName() {
+		return fileName;
+	}
+}

+ 161 - 0
src/main/java/com/lsw/commons/utils/FileUtil.java

@@ -0,0 +1,161 @@
+package com.lsw.commons.utils;
+
+import com.jfinal.core.JFinal;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 文件操作工具类
+ * @time 2016814
+ */
+public class FileUtil {
+    /**
+     * 文件/目录 重命名
+     *
+     * @param oldPath 原有路径(绝对路径)
+     * @param newPath 更新路径
+     */
+    public static boolean renameFile(String oldPath, String newPath) {
+        boolean success = false;
+        File oldFile = new File(oldPath);// 文件或目录
+        File newFile = new File(newPath);// 文件或目录
+        try {
+            success = oldFile.renameTo(newFile);// 重命名
+            if (!success) {
+                System.out.println("重命名失败");
+            } else {
+                System.out.println("重命名成功");
+            }
+        } catch (RuntimeException e) {
+            e.printStackTrace();
+        }
+        return success;
+
+    }
+
+    /**
+     * 删除单个文件
+     *
+     * @param Path 被删除文件的文件名
+     * @return 单个文件删除成功返回true,否则返回false
+     */
+    public static boolean deleteFile(String Path) {
+        boolean flag = false;
+        File file = new File(Path);
+        // 路径为文件且不为空则进行删除
+        if (file.isFile() && file.exists()) {
+            file.delete();
+            flag = true;
+        }
+        return flag;
+    }
+
+    /**
+     * 删除目录(文件夹)以及目录下的文件
+     *
+     * @param sPath 被删除目录的文件路径
+     * @return 目录删除成功返回true,否则返回false
+     */
+    public static boolean deleteDirectory(String sPath) {
+        boolean flag = false;
+        // 如果sPath不以文件分隔符结尾,自动添加文件分隔符
+        if (!sPath.endsWith(File.separator)) {
+            sPath = sPath + File.separator;
+        }
+        File dirFile = new File(sPath);
+        // 如果dir对应的文件不存在,或者不是一个目录,则退出
+        if (!dirFile.exists() || !dirFile.isDirectory()) {
+            return false;
+        }
+        flag = true;
+        // 删除文件夹下的所有文件(包括子目录)
+        File[] files = dirFile.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            // 删除子文件
+            if (files[i].isFile()) {
+                flag = deleteFile(files[i].getAbsolutePath());
+                if (!flag)
+                    break;
+            } // 删除子目录
+            else {
+                flag = deleteDirectory(files[i].getAbsolutePath());
+                if (!flag)
+                    break;
+            }
+        }
+        if (!flag)
+            return false;
+        // 删除当前目录
+        if (dirFile.delete()) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 读取某个文件夹下的所有文件
+     *
+     * @param filepath 路径
+     * @return
+     */
+    public static List<FileEntity> readfile(String filepath) {
+        List<FileEntity> list = new ArrayList<FileEntity>();
+        try {
+            File file = new File(filepath);
+            if (!file.isDirectory()) {
+                System.out.println("文件");
+                list.add(new FileEntity(file.getPath(), file.getName()));
+            } else if (file.isDirectory()) {
+                System.out.println("文件夹");
+                String[] filelist = file.list();
+                for (int i = 0; i < filelist.length; i++) {
+                    File readfile = new File(filepath + "\\" + filelist[i]);
+                    if (!readfile.isDirectory()) {
+                        list.add(new FileEntity(readfile.getPath(), readfile.getName()));
+                    } else if (readfile.isDirectory()) {
+                        readfile(filepath + "\\" + filelist[i]);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            System.out.println("readfile()   Exception:" + e.getMessage());
+        }
+        return list;
+    }
+
+    public static String getPrintSize(long size) {
+        // 如果字节数少于1024,则直接以B为单位,否则先除于1024,后3位因太少无意义
+        double value = (double) size;
+        if (value < 1024) {
+            return String.valueOf(value) + "B";
+        } else {
+            value = new BigDecimal(value / 1024).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
+        }
+        // 如果原字节数除于1024之后,少于1024,则可以直接以KB作为单位
+        // 因为还没有到达要使用另一个单位的时候
+        // 接下去以此类推
+        if (value < 1024) {
+            return String.valueOf(value) + "KB";
+        } else {
+            value = new BigDecimal(value / 1024).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
+        }
+        if (value < 1024) {
+            return String.valueOf(value) + "MB";
+        } else {
+            // 否则如果要以GB为单位的,先除于1024再作同样的处理
+            value = new BigDecimal(value / 1024).setScale(2, BigDecimal.ROUND_DOWN).doubleValue();
+            return String.valueOf(value) + "GB";
+        }
+    }
+
+    public static void main(String[] args) {
+       boolean a= deleteFile("E:\\idea\\work2\\frcz_service\\src\\main\\webapp\\upload\\file\\网赚数据结构1.doc");
+        System.out.println(a);
+
+    }
+}

+ 63 - 0
src/main/java/com/lsw/commons/utils/HttpServletRequestWrapper.java

@@ -0,0 +1,63 @@
+package com.lsw.commons.utils;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class HttpServletRequestWrapper extends javax.servlet.http.HttpServletRequestWrapper {
+
+	private HttpServletRequest request;
+
+	public HttpServletRequestWrapper(HttpServletRequest request) {
+		super(request);
+		this.request = request;
+	}
+
+	/**
+	 * 重写getParameter方法
+	 */
+	@Override
+	public String getParameter(String name) {
+		String value = this.request.getParameter(name);
+		if (value == null)
+			return null;
+		value = format(value);
+		return value;
+	}
+
+	public String filter(String message) {
+		if (message == null)
+			return (null);
+		message = format(message);
+		return message;
+	}
+
+	/**
+	 * 统一处理特殊字符的方法
+	 * 
+	 * @param name
+	 *            要替换的字符
+	 * @return
+	 */
+	private String format(String name) {
+		// 注意该方法,替换的字符前后数组长度要一一对应,我这里将特殊的字符要替换为空
+		name = name.replace("\\", "");
+		name = name.replace("<", "");
+		name = name.replace(">", "");
+		name = name.replace("window", "");
+		name = name.replace(".location", "");
+		name = name.replace(".js", "");
+		name = name.replace("%", "");
+		name = name.replace(".JS", "");
+		name = name.replace(".php", "");
+		name = name.replace("javascript", "");
+		name = name.replace("script", "");
+		name = name.replace("sCrIpT", "");
+		name = name.replace("SCRIPT", "");
+		name = name.replace("document", "");
+		name = name.replace("cookie", "");
+		name = name.replace("alert", "");
+		name = name.replace("ALERT", "");
+		name = name.replace("select", "");
+		name = name.replace("SELECT", "");
+		return name;
+	}
+}

+ 260 - 0
src/main/java/com/lsw/commons/utils/ImageKit.java

@@ -0,0 +1,260 @@
+package com.lsw.commons.utils;
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import com.jfinal.kit.StrKit;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+
+/**
+ * ImageKit 图片高保真缩放与裁剪,不依赖于任何第三方库
+ */
+public class ImageKit {
+
+	private final static String[] imgExts = new String[]{"jpg", "jpeg", "png", "bmp","gif"};
+	private final static String[] video = new String[]{"mp4", "avi", "mkv", "wmv","flv"};
+	private final static String[] apk = new String[]{"apk"};
+
+	public static String getExtName(String fileName) {
+		int index = fileName.lastIndexOf('.');
+		if (index != -1 && (index + 1) < fileName.length()) {
+			return fileName.substring(index + 1);
+		} else {
+			return null;
+		}
+	}
+
+	/**
+	 * 通过文件扩展名,判断是否是视频文件,支持则返回 true,否则返回 false
+	 */
+	public static boolean isVideo(String fileName) {
+		if (StrKit.isBlank(fileName)) {
+			return false;
+		}
+		fileName = fileName.trim().toLowerCase();
+		String ext = getExtName(fileName);
+		if (ext != null) {
+			for (String s : video) {
+				if (s.equals(ext)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+	/**
+	 * 通过文件扩展名,判断是否是安卓apk,支持则返回 true,否则返回 false
+	 */
+	public static boolean isApk(String fileName) {
+		if (StrKit.isBlank(fileName)) {
+			return false;
+		}
+		fileName = fileName.trim().toLowerCase();
+		String ext = getExtName(fileName);
+		if (ext != null) {
+			for (String s : apk) {
+				if (s.equals(ext)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+	/**
+	 * 通过文件扩展名,判断是否为支持的图像文件,支持则返回 true,否则返回 false
+	 */
+	public static boolean isImageExtName(String fileName) {
+		if (StrKit.isBlank(fileName)) {
+			return false;
+		}
+		fileName = fileName.trim().toLowerCase();
+		String ext = getExtName(fileName);
+		if (ext != null) {
+			for (String s : imgExts) {
+				if (s.equals(ext)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+	public static final boolean notImageExtName(String fileName) {
+		return ! isImageExtName(fileName);
+	}
+	public static final boolean isVideoFile(String fileName) {
+		return ! isVideo(fileName);
+	}
+    public static final boolean isApkFile(String fileName) {
+        return ! isApk(fileName);
+    }
+
+	public static BufferedImage loadImageFile(String sourceImageFileName) {
+		if (notImageExtName(sourceImageFileName)) {
+			throw new IllegalArgumentException("只支持如下几种类型的图像文件:jpg、jpeg、png、bmp");
+		}
+
+		File sourceImageFile = new File(sourceImageFileName);
+		if (!sourceImageFile.exists() || !sourceImageFile.isFile()) {
+			throw new IllegalArgumentException("文件不存在");
+		}
+
+		try {
+			return ImageIO.read(sourceImageFile);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * 以 maxWidth 为界对图像进行缩放,高保真保存
+	 * 1:当图像 width > maxWidth 时,将宽度变为 maxWidth,高度等比例进行缩放,高保真保存
+	 * 2:当图像 width <= maxWidth 时,宽高保持不变,只进行高保真保存
+	 */
+	public static void zoom(int maxWidth, File srcFile, String saveFile) {
+		float quality = 0.8f;
+
+		try {
+			BufferedImage srcImage = ImageIO.read(srcFile);
+			int srcWidth = srcImage.getWidth();
+			int srcHeight = srcImage.getHeight();
+
+			// 当宽度在 maxWidth 范围之内,不改变图像宽高,只进行图像高保真保存
+			if (srcWidth <= maxWidth) {
+				/**
+				 * 如果图像不进行缩放的话, resize 就没有必要了,
+				 * 经过测试是否有 resize 这一步,生成的结果图像完全一样,一个字节都不差
+				 * 所以删掉 resize,可以提升性能,少一步操作
+				 */
+				// BufferedImage ret = resize(srcImage, srcWidth, srcHeight);
+				// saveWithQuality(ret, quality, saveFile);
+				saveWithQuality(srcImage, quality, saveFile);
+			}
+			// 当宽度超出 maxWidth 范围,将宽度变为 maxWidth,而高度按比例变化
+			else {
+				float scalingRatio = (float)maxWidth / (float)srcWidth;			// 计算缩放比率
+				float maxHeight = ((float)srcHeight * scalingRatio);	// 计算缩放后的高度
+				BufferedImage ret = resize(srcImage, maxWidth, (int)maxHeight);
+				saveWithQuality(ret, quality, saveFile);
+			}
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * 对图片进行剪裁,只保存选中的区域
+	 * @param sourceImageFile 原图
+	 * @param left
+	 * @param top
+	 * @param width
+	 * @param height
+	 */
+	public static BufferedImage crop(String sourceImageFile, int left, int top, int width, int height) {
+		if (notImageExtName(sourceImageFile)) {
+			throw new IllegalArgumentException("只支持如下几种类型的图像文件:jpg、jpeg、png、bmp");
+		}
+
+		try {
+			BufferedImage bi = ImageIO.read(new File(sourceImageFile));
+			width = Math.min(width, bi.getWidth());
+			height = Math.min(height, bi.getHeight());
+			if(width <= 0) width = bi.getWidth();
+			if(height <= 0) height = bi.getHeight();
+
+			left = Math.min(Math.max(0, left), bi.getWidth() - width);
+			top = Math.min(Math.max(0, top), bi.getHeight() - height);
+
+			BufferedImage subImage = bi.getSubimage(left, top, width, height);
+			return subImage;	// return ImageIO.write(bi, "jpeg", fileDest);
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	public static void save(BufferedImage bi, String outputImageFile) {
+		FileOutputStream newImage = null;
+		try {
+			// ImageIO.write(bi, "jpg", new File(outputImageFile));
+			ImageIO.write(bi, getExtName(outputImageFile), new File(outputImageFile));
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (newImage != null) {
+				try {
+					newImage.close();
+				} catch (IOException e) {
+					throw new RuntimeException(e);
+				}
+			}
+		}
+	}
+
+	/**
+	 * 高保真缩放
+	 */
+	public static BufferedImage resize(BufferedImage bi, int toWidth, int toHeight) {
+		Graphics g = null;
+		try {
+			// 从 BufferedImage 对象中获取一个经过缩放的 image
+			Image scaledImage = bi.getScaledInstance(toWidth, toHeight, Image.SCALE_SMOOTH);
+			// 创建 BufferedImage 对象,存放缩放过的 image
+			BufferedImage ret = new BufferedImage(toWidth, toHeight, BufferedImage.TYPE_INT_RGB);
+			g = ret.getGraphics();
+			g.drawImage(scaledImage, 0, 0, null);
+			return ret;
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (g != null) {
+				g.dispose();
+			}
+		}
+	}
+
+	/**
+	 * jfinal.com 使用参数为宽:200, 高:200, 质量:0.8
+	 * 生成大小为:6.79 KB (6,957 字节)
+	 *
+	 * 如果使用参数为宽:120, 高:120, 质量:0.8
+	 * 则生成的图片大小为:3.45 KB (3,536 字节)
+	 *
+	 * 如果使用参数为宽:300, 高:300, 质量:0.5
+	 * 则生成的图片大小为:7.54 KB (7,725 字节)
+	 *
+	 *
+	 * 建议使用 0.8 的 quality 并且稍大点的宽高
+	 * 只选用两种质量:0.80.9,这两个差别不是很大,
+	 * 但是如果尺寸大些的话,选用 0.80.9 要划算,因为占用的空间差不多的时候,尺寸大些的更清晰
+	 */
+	public static void saveWithQuality(BufferedImage im, float quality, String outputImageFile) {
+		FileOutputStream newImage = null;
+		try {
+			/* 输出到文件流 */
+			newImage = new FileOutputStream(outputImageFile);
+			JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newImage);
+			JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(im);
+			/* 压缩质量, 0.75 就算是高质量 */
+			jep.setQuality(quality, true);	// jep.setQuality(0.9f, true);
+			encoder.encode(im, jep);
+			/* 近JPEG编码 */
+			// newImage.close();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			if (newImage != null) {
+				try {newImage.close();} catch (IOException e) {throw new RuntimeException(e);}
+			}
+		}
+	}
+}
+
+

+ 170 - 0
src/main/java/com/lsw/commons/utils/ImageZipUtil.java

@@ -0,0 +1,170 @@
+package com.lsw.commons.utils;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+public class ImageZipUtil {
+	/**
+	 * 根据设置的宽高等比例压缩图片文件<br>
+	 * 先保存原文件,再压缩、上传
+	 * 
+	 * @param oldFile
+	 *            要进行压缩的文件
+	 * @param newFile
+	 *            新文件
+	 * @return 返回压缩后的文件的全路径
+	 */
+	public static String zipImageFile(File oldFile, File newFile) {
+		if (oldFile == null) {
+			return null;
+		}
+		try {
+			/** 对服务器上的临时文件进行处理 */
+			Image srcFile = ImageIO.read(oldFile);
+			int w = srcFile.getWidth(null);
+			int h = srcFile.getHeight(null);
+			int w1=w;
+			int h1=h;
+			if(w<800&&w>200){
+				w1=(int) (w-w*0.3);
+				h1=(int) (h-h*0.3);
+			}else if (w<1600&&w>800) {
+				w1=(int) (w-w*0.4);
+				h1=(int) (h-h*0.4);
+			}else if (w<2500&&w>1600) {
+				w1=(int) (w-w*0.45);
+				h1=(int) (h-h*0.45);
+			}else if (w<4100&&w>2500) {
+				w1=(int) (w-w*0.5);
+				h1=(int) (h-h*0.5);
+			}
+			String srcImgPath = newFile.getAbsoluteFile().toString();
+			String subfix = "jpg";
+			subfix = srcImgPath.substring(srcImgPath.lastIndexOf(".") + 1, srcImgPath.length());
+
+			BufferedImage buffImg = null;
+			if (subfix.equals("png")) {
+				buffImg = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_ARGB);
+			} else {
+				buffImg = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
+			}
+			Graphics2D graphics = buffImg.createGraphics();
+			graphics.setBackground(new Color(255, 255, 255));
+			graphics.setColor(new Color(255, 255, 255));
+			graphics.fillRect(0, 0, w1, h1);
+			graphics.drawImage(srcFile.getScaledInstance(w1, h1, Image.SCALE_SMOOTH), 0, 0, null);
+			ImageIO.write(buffImg, subfix, new File(srcImgPath));
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return newFile.getAbsolutePath();
+	}
+
+	/**
+	 * 根据设置的宽高等比例压缩图片文件<br>
+	 * 先保存原文件,再压缩、上传
+	 *
+	 * @param oldFile
+	 *            要进行压缩的文件
+	 * @param newFile
+	 *            新文件
+	 * @return 返回压缩后的文件的全路径
+	 */
+	public static String zipImageFile(File oldFile, File newFile,double display) {
+		if (oldFile == null) {
+			return null;
+		}
+		try {
+			/** 对服务器上的临时文件进行处理 */
+			Image srcFile = ImageIO.read(oldFile);
+			int w = srcFile.getWidth(null);
+			int h = srcFile.getHeight(null);
+			int w1=w;
+			int h1=h;
+			w1=(int) (w-w*display);
+			h1=(int) (h-h*display);
+			String srcImgPath = newFile.getAbsoluteFile().toString();
+			String subfix = "jpg";
+			subfix = srcImgPath.substring(srcImgPath.lastIndexOf(".") + 1, srcImgPath.length());
+
+			BufferedImage buffImg = null;
+			if (subfix.equals("png")) {
+				buffImg = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_ARGB);
+			} else {
+				buffImg = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB);
+			}
+			Graphics2D graphics = buffImg.createGraphics();
+			graphics.setBackground(new Color(255, 255, 255));
+			graphics.setColor(new Color(255, 255, 255));
+			graphics.fillRect(0, 0, w1, h1);
+			graphics.drawImage(srcFile.getScaledInstance(w1, h1, Image.SCALE_SMOOTH), 0, 0, null);
+			ImageIO.write(buffImg, subfix, new File(srcImgPath));
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return newFile.getAbsolutePath();
+	}
+
+	/**
+	 * 按设置的宽度高度压缩图片文件<br>
+	 * 先保存原文件,再压缩、上传
+	 * 
+	 * @param oldFile
+	 *            要进行压缩的文件全路径
+	 * @param newFile
+	 *            新文件
+	 * @param width
+	 *            宽度
+	 * @param height
+	 *            高度
+	 * @param quality
+	 *            质量
+	 * @return 返回压缩后的文件的全路径
+	 */
+	public static String zipWidthHeightImageFile(File oldFile, File newFile, int width, int height, float quality) {
+		if (oldFile == null) {
+			return null;
+		}
+		String newImage = null;
+		try {
+			/** 对服务器上的临时文件进行处理 */
+			Image srcFile = ImageIO.read(oldFile);
+
+			String srcImgPath = newFile.getAbsoluteFile().toString();
+			System.out.println(srcImgPath);
+			String subfix = "jpg";
+			subfix = srcImgPath.substring(srcImgPath.lastIndexOf(".") + 1, srcImgPath.length());
+
+			BufferedImage buffImg = null;
+			if (subfix.equals("png")) {
+				buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+			} else {
+				buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+			}
+
+			Graphics2D graphics = buffImg.createGraphics();
+			graphics.setBackground(new Color(255, 255, 255));
+			graphics.setColor(new Color(255, 255, 255));
+			graphics.fillRect(0, 0, width, height);
+			graphics.drawImage(srcFile.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
+
+			ImageIO.write(buffImg, subfix, new File(srcImgPath));
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return newImage;
+	}
+}

+ 59 - 0
src/main/java/com/lsw/commons/utils/IpUtil.java

@@ -0,0 +1,59 @@
+package com.lsw.commons.utils;
+
+import com.jfinal.json.FastJson;
+import com.jfinal.kit.HttpKit;
+import com.jfinal.kit.StrKit;
+
+import javax.servlet.http.HttpServletRequest;
+import java.net.UnknownHostException;
+import java.util.Map;
+
+public class IpUtil {
+    /**
+     * 获取ip地址信息
+     *
+     * @return
+     * @throws UnknownHostException
+     */
+    public static Map<String, Object> getAddress(String ip) throws UnknownHostException {
+        String returnStr = HttpKit.get("http://ip.taobao.com/service/getIpInfo.php?ip=" + ip);
+        Map<String, Object> result = FastJson.getJson().parse(returnStr, Map.class);
+        result.put("ip", ip);
+        if (0 == Integer.parseInt(result.get("code").toString())) {
+            return (Map<String, Object>) result.get("data");
+        } else {
+            result.put("result", false);
+            return result;
+        }
+    }
+    /**
+     * 获取访问用户的客户端IP(适用于公网与局域网).
+     */
+    public static final String getIpAddr(final HttpServletRequest request)
+            throws Exception {
+        if (request == null) {
+            throw (new Exception("getIpAddr method HttpServletRequest Object is null"));
+        }
+        String ipString = request.getHeader("x-forwarded-for");
+        if (StrKit.isBlank(ipString) || "unknown".equalsIgnoreCase(ipString)) {
+            ipString = request.getHeader("Proxy-Client-IP");
+        }
+        if (StrKit.isBlank(ipString) || "unknown".equalsIgnoreCase(ipString)) {
+            ipString = request.getHeader("WL-Proxy-Client-IP");
+        }
+        if (StrKit.isBlank(ipString) || "unknown".equalsIgnoreCase(ipString)) {
+            ipString = request.getRemoteAddr();
+        }
+
+        // 多个路由时,取第一个非unknown的ip
+        final String[] arr = ipString.split(",");
+        for (final String str : arr) {
+            if (!"unknown".equalsIgnoreCase(str)) {
+                ipString = str;
+                break;
+            }
+        }
+
+        return ipString;
+    }
+}

+ 38 - 0
src/main/java/com/lsw/commons/utils/Message.java

@@ -0,0 +1,38 @@
+package com.lsw.commons.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.jfinal.json.FastJson;
+import com.jfinal.kit.HttpKit;
+
+/**
+ * @author 李书文
+ * @description 发送短信验证
+ * @time 20161116
+ */
+@SuppressWarnings("unchecked")
+public class Message {
+
+    /**
+     * @param type  0:注册,1:找回密码
+     * @param phone 手机号
+     * @param code  验证码
+     * @return
+     */
+    public static boolean sendMessage(int type, String phone, String code) {
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("key", "91c36810a9c84e7cb3dcd145b1735e45");
+        params.put("mobile", phone);
+        params.put("templateId", type == 0 ? "ea207fd7f089438d95d24b3b56b15614" : "779b822b2f2d4a0c8c34099e15ae119f");
+        params.put("param", code);
+        Map<String, Object> result = FastJson.getJson().parse(HttpKit.get("http://v1.avatardata.cn/Sms/Send", params), Map.class);
+        if (Boolean.parseBoolean(result.get("success").toString())) {
+            return true;
+        }
+        return false;
+    }
+
+    public static void main(String[] args) {
+    }
+}

+ 58 - 0
src/main/java/com/lsw/commons/utils/RuntimeUtil.java

@@ -0,0 +1,58 @@
+package com.lsw.commons.utils;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * 
+ * @author 李书文
+ * @description 获取系统信息工具类
+ * @time 20161022
+ */
+public class RuntimeUtil {
+
+	public static void main(String[] args) {
+
+	}
+
+	public static Map<String, Object> property() throws UnknownHostException {
+		Map<String, Object> object = new HashMap<String, Object>();
+		Runtime r = Runtime.getRuntime();
+		Properties props = System.getProperties();
+		InetAddress addr;
+		addr = InetAddress.getLocalHost();
+		String ip = addr.getHostAddress();
+		Map<String, String> map = System.getenv();
+		String userName = map.get("USERNAME");// 获取用户名
+		String computerName = map.get("COMPUTERNAME");// 获取计算机名
+
+		object.put("userName", userName);
+		object.put("computerName", computerName);
+		object.put("ip", ip);
+		object.put("HostName", addr.getHostName());
+		object.put("Memory", r.totalMemory());
+		object.put("freeMemory", r.freeMemory());
+		object.put("Processors", r.availableProcessors());
+		object.put("version", props.getProperty("java.version"));
+		object.put("vendor", props.getProperty("java.vendor"));
+		object.put("home", props.getProperty("java.home"));
+		object.put("specification", props.getProperty("java.specification.version"));
+		return object;
+	}
+
+	public static String getIp() {
+		InetAddress addr;
+		String ip = "";
+		try {
+			addr = InetAddress.getLocalHost();
+			ip = addr.getHostAddress();
+		} catch (UnknownHostException e) {
+			e.printStackTrace();
+		}
+		return ip;
+
+	}
+}

+ 191 - 0
src/main/java/com/lsw/commons/utils/SQL.java

@@ -0,0 +1,191 @@
+package com.lsw.commons.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 
+ * @author 李书文
+ * @description 数据库参数拼接工具
+ * @time 20161021
+ */
+
+public class SQL {
+
+	private String select; // select语句
+	private String fromClause; // from子句
+	private StringBuffer whereClause = new StringBuffer(""); // where子句
+	private StringBuffer orderByClause = new StringBuffer(""); // order by子句
+
+	private List<Object> parameters = new ArrayList<Object>(); // 参数列表
+
+	/**
+	 * 用于一张表的情况,生成From子句
+	 * 
+	 * from topic t
+	 */
+	public SQL(String select, String tableName, String alias) {
+		this.select = select;
+		fromClause = new StringBuffer(" from ").append(tableName).append(" ").append(alias).toString();
+	}
+
+	/**
+	 * 用于left join 这种可以写在一个from字句中
+	 */
+	public SQL(String select, String from) {
+		this.select = select;
+		fromClause = new StringBuffer(" from ").append(from).toString();
+	}
+
+	/**
+	 * 用于两张表联合的情况,生成From子句,类似from table1 a,table2 b 然后添加where条件
+	 * 这个方法的调用格式为("select...","table1","alias1","table2","alias2"...),至少两对,
+	 * 如果只有一个表, 那就按照第一个构造方法调用 。后面的表和别名是一对一对出现的
+	 */
+	public SQL(String select, String[] table_alias) {
+		if (table_alias.length <= 2 || table_alias.length % 2 != 0) {
+			throw new RuntimeException("你的参数有误,请看该方法的说明");
+		}
+		this.select = select;
+		StringBuffer buffer = new StringBuffer(" from ");
+
+		int group = table_alias.length / 2;// 有这么多个表
+		for (int i = 0; i < group; i++) {
+			buffer.append(table_alias[i * 2]).append(" " + table_alias[i * 2 + 1]).append(",");
+		}
+		buffer.deleteCharAt(buffer.length() - 1);
+		fromClause = buffer.toString();
+	}
+
+	/**
+	 * 拼接where子句 d.id between ? and ? d.parent=? d.parent is null
+	 * 
+	 * @param condition
+	 * @param params
+	 */
+	public SQL add(String condition, Object... params) {
+		// 拼接
+		if (whereClause.length() == 0) {
+			whereClause = new StringBuffer(" where ").append(condition);
+		} else {
+			whereClause.append(" and ").append(condition);
+		}
+
+		// 参数
+		if (params != null) {
+			for (Object p : params) {
+				parameters.add(p);
+			}
+		}
+
+		return this;
+	}
+
+	/**
+	 * 如果第一个参数为true,则拼接where子句
+	 * 
+	 * @param append
+	 * @param condition
+	 * @param params
+	 */
+	public SQL add(boolean append, String condition, Object... params) {
+		if (append) {
+			add(condition, params);
+		}
+		return this;
+	}
+
+	/**
+	 * 拼接order by子句
+	 * 
+	 * @param propertyName
+	 *            参与排序的属性名
+	 * @param asc
+	 *            true表示升序,false表示降序
+	 */
+	public SQL addOrderProperty(String propertyName, boolean asc) {
+		if (orderByClause.length() == 0) {
+			orderByClause = new StringBuffer(" order by ").append(propertyName + (asc ? " asc" : " desc"));
+		} else {
+			orderByClause.append(", ").append(propertyName + (asc ? " asc" : " desc"));
+		}
+		return this;
+	}
+
+	/**
+	 * 如果第一个参数为true,则拼接order by子句
+	 * 
+	 * @param append
+	 * @param propertyName
+	 * @param asc
+	 */
+	public SQL addOrderProperty(boolean append, String propertyName, boolean asc) {
+		if (append) {
+			addOrderProperty(propertyName, asc);
+		}
+		return this;
+	}
+
+	public String getSelect() {
+		return this.select;
+	}
+
+	/**
+	 * 获取生成的用于查询数据列表的sqlExceptSelect语句
+	 * 
+	 * @return
+	 */
+	public String getSqlExceptSelect() {
+		// 这里面含有一些?,下面来填充
+		String sqlExceptSelect = new StringBuffer(fromClause).append(whereClause).append(orderByClause).toString();
+		// 填充参数
+		if (parameters != null) { // 设置参数
+			for (int i = 0; i < parameters.size(); i++) {
+				// 巧妙利用替换一次之后,后面的?就自动往前移动一位,那么replaceFirst每次替换的就是下一个?
+				sqlExceptSelect = sqlExceptSelect.replaceFirst("\\?", "'" + parameters.get(i) + "'");
+			}
+		}
+		return sqlExceptSelect;
+	}
+
+	/**
+	 * 获取生成的用于查询总记录数的SQL语句
+	 * 
+	 * @return
+	 */
+	public String getCountQuerySql() {
+		return "select count(*) " + fromClause + whereClause;
+	}
+
+	/**
+	 * 获取SQL中的参数值列表
+	 * 
+	 * @return
+	 */
+	public Object[] getParameters() {
+		return parameters.toArray();
+	}
+
+	/**
+	 * 获取生成的用于查询数据列表的sqlExceptSelect语句,里面可能含有?,需要配合getParameters
+	 * 
+	 * @return
+	 */
+	public String getSqlExceptSelectWithPadding() {
+		// 这里面含有一些?,下面来填充
+		String sqlExceptSelect = new StringBuffer(fromClause).append(whereClause).append(orderByClause).toString();
+		return sqlExceptSelect;
+	}
+
+	public static void main(String[] args) {
+		//String tables[]={"tb_admin ta","left join tb_user a on a.id=ta.id"};
+		SQL sql = new SQL("select *", "tb_admin ta " + "left join tb_user a on a.id=ta.id");
+		sql.add("barchId=" + "1111");
+		sql.add("bas=" + "1111");
+		sql.add("createTime between=" + "2016-10-21");
+		sql.add("2016-10-21");
+		sql.addOrderProperty(true, "id", false);
+		System.out.println(sql.getSelect()+sql.getSqlExceptSelect());
+      
+	}
+}

+ 155 - 0
src/main/java/com/lsw/commons/utils/SendMessage.java

@@ -0,0 +1,155 @@
+package com.lsw.commons.utils;
+
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.profile.DefaultProfile;
+import com.aliyuncs.profile.IClientProfile;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Created on 17/6/7.
+ * 短信API产品的DEMO程序,工程中包含了一个SmsDemo类,直接通过
+ * 执行main函数即可体验短信产品API功能(只需要将AK替换成开通了云通信-短信产品功能的AK即可)
+ * 工程依赖了2个jar包(存放在工程的libs目录下)
+ * 1:aliyun-java-sdk-core.jar
+ * 2:aliyun-java-sdk-dysmsapi.jar
+ * <p>
+ * 备注:Demo工程编码采用UTF-8
+ * 国际短信发送请勿参照此DEMO
+ */
+public class SendMessage {
+
+    //产品名称:云通信短信API产品,开发者无需替换
+    static final String product = "Dysmsapi";
+    //产品域名,开发者无需替换
+    static final String domain = "dysmsapi.aliyuncs.com";
+
+    // TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
+    static final String accessKeyId = "LTAICvBRpe5lqhDl";
+    static final String accessKeySecret = "NukmQBarYzgFjriRrsT2I0kzQ8iwK4";
+
+    /**
+     * @param phone        手机号
+     * @param SignName     短信签名
+     * @param TemplateCode 短信模板
+     * @param Param        模板内容
+     * @return
+     * @throws ClientException
+     */
+    public static boolean sendSms(String phone, String SignName, String TemplateCode, String Param) {
+
+        //可自助调整超时时间
+        SendSmsResponse response = null;
+        try {
+            System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
+            System.setProperty("sun.net.client.defaultReadTimeout", "10000");
+
+            //初始化acsClient,暂不支持region化
+            IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
+            DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
+            IAcsClient acsClient = new DefaultAcsClient(profile);
+
+            //组装请求对象-具体描述见控制台-文档部分内容
+            SendSmsRequest request = new SendSmsRequest();
+            //必填:待发送手机号
+            request.setPhoneNumbers(phone);
+            //必填:短信签名-可在短信控制台中找到
+            request.setSignName(SignName);
+            //必填:短信模板-可在短信控制台中找到
+            request.setTemplateCode(TemplateCode);
+            //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
+            request.setTemplateParam(Param);
+
+            //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
+            //request.setSmsUpExtendCode("90997");
+
+            //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
+            //request.setOutId("yourOutId");
+            //hint 此处可能会抛出异常,注意catch
+            response = acsClient.getAcsResponse(request);
+        } catch (ClientException e) {
+            e.printStackTrace();
+            return false;
+        }
+        if (response.getCode() != null && response.getCode().equals("OK")) {
+            return true;
+        }
+        return false;
+    }
+
+
+    public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException {
+
+        //可自助调整超时时间
+        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
+        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
+
+        //初始化acsClient,暂不支持region化
+        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
+        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
+        IAcsClient acsClient = new DefaultAcsClient(profile);
+
+        //组装请求对象
+        QuerySendDetailsRequest request = new QuerySendDetailsRequest();
+        //必填-号码
+        request.setPhoneNumber("15000000000");
+        //可选-流水号
+        request.setBizId(bizId);
+        //必填-发送日期 支持30天内记录查询,格式yyyyMMdd
+        SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
+        request.setSendDate(ft.format(new Date()));
+        //必填-页大小
+        request.setPageSize(10L);
+        //必填-当前页码从1开始计数
+        request.setCurrentPage(1L);
+
+        //hint 此处可能会抛出异常,注意catch
+        QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request);
+
+        return querySendDetailsResponse;
+    }
+
+
+/*    public static void main(String[] args) throws ClientException, InterruptedException {
+
+        //发短信
+        SendSmsResponse response = sendSms("13097850972", "法润賨州", "SMS_107925034", JsonKit.toJson(Kv.by("code", 123456)));
+        System.out.println("短信接口返回的数据----------------");
+        System.out.println("Code=" + response.getCode());
+        System.out.println("Message=" + response.getMessage());
+        System.out.println("RequestId=" + response.getRequestId());
+        System.out.println("BizId=" + response.getBizId());
+
+        Thread.sleep(3000L);
+
+        //查明细
+        if (response.getCode() != null && response.getCode().equals("OK")) {
+            QuerySendDetailsResponse querySendDetailsResponse = querySendDetails(response.getBizId());
+            System.out.println("短信明细查询接口返回数据----------------");
+            System.out.println("Code=" + querySendDetailsResponse.getCode());
+            System.out.println("Message=" + querySendDetailsResponse.getMessage());
+            int i = 0;
+            for (QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO : querySendDetailsResponse.getSmsSendDetailDTOs()) {
+                System.out.println("SmsSendDetailDTO[" + i + "]:");
+                System.out.println("Content=" + smsSendDetailDTO.getContent());
+                System.out.println("ErrCode=" + smsSendDetailDTO.getErrCode());
+                System.out.println("OutId=" + smsSendDetailDTO.getOutId());
+                System.out.println("PhoneNum=" + smsSendDetailDTO.getPhoneNum());
+                System.out.println("ReceiveDate=" + smsSendDetailDTO.getReceiveDate());
+                System.out.println("SendDate=" + smsSendDetailDTO.getSendDate());
+                System.out.println("SendStatus=" + smsSendDetailDTO.getSendStatus());
+                System.out.println("Template=" + smsSendDetailDTO.getTemplateCode());
+            }
+            System.out.println("TotalCount=" + querySendDetailsResponse.getTotalCount());
+            System.out.println("RequestId=" + querySendDetailsResponse.getRequestId());
+        }
+
+    }*/
+}

+ 335 - 0
src/main/java/com/lsw/commons/utils/TimeUtil.java

@@ -0,0 +1,335 @@
+package com.lsw.commons.utils;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * @author 李书文
+ * @description 时间工具类
+ * @time 2016813
+ */
+public class TimeUtil {
+    public static List<Map<String, Object>> list;
+    private final static ThreadLocal<SimpleDateFormat> timeFormater = new ThreadLocal<SimpleDateFormat>() {
+        @Override
+        protected SimpleDateFormat initialValue() {
+            return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        }
+    };
+    private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
+        @Override
+        protected SimpleDateFormat initialValue() {
+            return new SimpleDateFormat("yyyy-MM-dd");
+        }
+    };
+
+    /**
+     * 格式化日期(精确到秒)
+     *
+     * @return
+     */
+    public static String getNow() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return format.format(System.currentTimeMillis());
+    }
+
+    /**
+     * 格式化日期(精确到秒)
+     *
+     * @return
+     */
+    public static String getTIME() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
+        return format.format(System.currentTimeMillis());
+    }
+
+    /**
+     * 格式化日期(精确到天)
+     *
+     * @return
+     */
+    public static String getDay() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        return format.format(System.currentTimeMillis());
+    }
+
+    public static String getDayFormat() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy年-MM月-dd日");
+        return format.format(System.currentTimeMillis());
+    }
+
+    //获取时分
+    public static String getHour() {
+        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
+        return format.format(System.currentTimeMillis());
+    }
+
+    public static List<Map<String, Object>> printWeekdays() {
+        list = new ArrayList<Map<String, Object>>();
+        Calendar calendar = Calendar.getInstance();
+        for (int i = 0; i < 7; i++) {
+            printDay(calendar);
+            calendar.add(Calendar.DATE, 1);
+        }
+        return list;
+    }
+
+    private static String printDay(Calendar calendar) {
+        SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
+        SimpleDateFormat dateFormat2 = new SimpleDateFormat("MM");
+        SimpleDateFormat dateFormat3 = new SimpleDateFormat("dd");
+        SimpleDateFormat dateFormat4 = new SimpleDateFormat("EE");
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("year", dateFormat1.format(calendar.getTime()));
+        map.put("month", dateFormat2.format(calendar.getTime()).replaceAll("^(0+)", "") + "月");
+        map.put("day", dateFormat3.format(calendar.getTime()));
+        map.put("week", dateFormat4.format(calendar.getTime()).replaceAll("^(星期+)", ""));
+        list.add(map);
+        return null;
+    }
+
+    /**
+     * 将日期格式转换成yyyy-MM-dd的字符串格式 返回值如:2016-8-13
+     *
+     * @param time 要转换的日期
+     * @return
+     */
+    public static String dateToString(Date time) {
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); // 定义将日期格式要换成的格式
+        String stringTime = formatter.format(time);
+        return stringTime;
+    }
+
+
+    /**
+     * 将字符串转为日期类型
+     *
+     * @param date
+     * @return
+     */
+    public static Date toDate(String date) {
+        return toDate(date, timeFormater.get());
+    }
+
+    public static Date toDate(String date, SimpleDateFormat dateFormater) {
+        try {
+            return dateFormater.parse(date);
+        } catch (ParseException e) {
+            return null;
+        }
+    }
+
+    /**
+     * 获取时间差
+     *
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @param format    时间格式 例如:yyyy-MM-dd HH:mm:ss
+     * @param str       计算 d:计算天数,h:计算小时,m:计算分钟
+     * @return
+     */
+    public static Long dateDiff(String startTime, String endTime, String format, String str) {
+        // 按照传入的格式生成一个simpledateformate对象
+        SimpleDateFormat sd = new SimpleDateFormat(format);
+        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
+        long nh = 1000 * 60 * 60;// 一小时的毫秒数
+        long nm = 1000 * 60;// 一分钟的毫秒数
+        long ns = 1000;// 一秒钟的毫秒数
+        long diff;
+        long day = 0;
+        long hour = 0;
+        long min = 0;
+        long sec = 0;
+        // 获得两个时间的毫秒时间差异
+        try {
+            diff = sd.parse(endTime).getTime() - sd.parse(startTime).getTime();
+            day = diff / nd;// 计算差多少天
+            hour = diff % nd / nh + day * 24;// 计算差多少小时
+            min = diff % nd % nh / nm + day * 24 * 60;// 计算差多少分钟
+            sec = diff % nd % nh % nm / ns;// 计算差多少秒
+            // 输出结果
+            System.out.println(
+                    "时间相差:" + day + "天" + (hour - day * 24) + "小时" + (min - day * 24 * 60) + "分钟" + sec + "秒。");
+            System.out.println("hour=" + hour + ",min=" + min);
+            if (str.equalsIgnoreCase("d")) {
+                return day;
+            } else if (str.equalsIgnoreCase("h")) {
+                return hour;
+            } else {
+                return min;
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        if (str.equalsIgnoreCase("h")) {
+            return hour;
+        } else {
+            return min;
+        }
+    }
+
+    /**
+     * 判断给定字符串时间是否为今日
+     *
+     * @param date
+     * @return boolean
+     */
+    public static boolean isToday(String date) {
+        boolean b = false;
+        Date time = toDate(date);
+        Date today = new Date();
+        if (time != null) {
+            String nowDate = dateFormater.get().format(today);
+            String timeDate = dateFormater.get().format(time);
+            if (nowDate.equals(timeDate)) {
+                b = true;
+            }
+        }
+        return b;
+    }
+
+    /**
+     * 获取当前日期是星期几
+     *
+     * @param date
+     * @return
+     */
+    public static int getWeekOfDate(Date date) {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(date);
+        int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
+        if (w < 0)
+            w = 0;
+        return w;
+    }
+
+    /**
+     * 判断当前日期是否是本周
+     *
+     * @param date
+     * @return
+     */
+    public static boolean isThisWeek(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        int currentWeek = calendar.get(Calendar.WEEK_OF_YEAR);
+        calendar.setTime(date);
+        int paramWeek = calendar.get(Calendar.WEEK_OF_YEAR);
+        if (paramWeek == currentWeek) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * 以友好的方式显示时间 如:xx分钟前,xx天前
+     *
+     * @param date
+     * @return
+     */
+    public static String friendly_time(String date) {
+        Date time = null;
+
+        if (isInEasternEightZones())
+            time = toDate(date);
+        else
+            time = transformTime(toDate(date), TimeZone.getTimeZone("GMT+08"), TimeZone.getDefault());
+
+        if (time == null) {
+            return "Unknown";
+        }
+        String ftime = "";
+        Calendar cal = Calendar.getInstance();
+
+        // 判断是否是同一天
+        String curDate = dateFormater.get().format(cal.getTime());
+        String paramDate = dateFormater.get().format(time);
+        if (curDate.equals(paramDate)) {
+            int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
+            if (hour == 0)
+                ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / 60000, 1) + "分钟前";
+            else
+                ftime = hour + "小时前";
+            return ftime;
+        }
+
+        long lt = time.getTime() / 86400000;
+        long ct = cal.getTimeInMillis() / 86400000;
+        int days = (int) (ct - lt);
+        if (days == 0) {
+            int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
+            if (hour == 0)
+                ftime = Math.max((cal.getTimeInMillis() - time.getTime()) / 60000, 1) + "分钟前";
+            else
+                ftime = hour + "小时前";
+        } else if (days == 1) {
+            ftime = "昨天";
+        } else if (days == 2) {
+            ftime = "前天 ";
+        } else if (days > 2 && days < 31) {
+            ftime = days + "天前";
+        } else if (days >= 31 && days <= 2 * 31) {
+            ftime = "一个月前";
+        } else if (days > 2 * 31 && days <= 3 * 31) {
+            ftime = "2个月前";
+        } else if (days > 3 * 31 && days <= 4 * 31) {
+            ftime = "3个月前";
+        } else {
+            ftime = dateFormater.get().format(time);
+        }
+        return ftime;
+    }
+
+    /**
+     * 判断用户的设备时区是否为东八区(中国) 2016815
+     *
+     * @return
+     */
+    public static boolean isInEasternEightZones() {
+        boolean defaultVaule = true;
+        if (TimeZone.getDefault() == TimeZone.getTimeZone("GMT+08"))
+            defaultVaule = true;
+        else
+            defaultVaule = false;
+        return defaultVaule;
+    }
+
+    /**
+     * 根据不同时区,转换时间 2016815
+     *
+     * @return
+     */
+    public static Date transformTime(Date date, TimeZone oldZone, TimeZone newZone) {
+        Date finalDate = null;
+        if (date != null) {
+            int timeOffset = oldZone.getOffset(date.getTime()) - newZone.getOffset(date.getTime());
+            finalDate = new Date(date.getTime() - timeOffset);
+        }
+        return finalDate;
+    }
+
+    /**
+     * 判断是否是过去的日期
+     *
+     * @param str 输入的日期
+     * @return true 早于现在,false 晚于现在
+     */
+    public static boolean isLaterThanNow(String str) {
+
+        boolean flag = false;
+        Date nowDate = new Date();
+        Date pastDate = null;
+        //格式化日期
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm", Locale.CHINA);
+        //在日期字符串非空时执行
+        try {
+            //将字符串转为日期格式,如果此处字符串为非合法日期就会抛出异常。
+            pastDate = sdf.parse(str);
+            //调用Date里面的before方法来做判断
+            flag = pastDate.before(nowDate);
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return flag;
+    }
+}

+ 94 - 0
src/main/java/com/lsw/controller/admin/system/department/DepartmentController.java

@@ -0,0 +1,94 @@
+package com.lsw.controller.admin.system.department;
+
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.model.Department;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 部门管理
+ * @time 2017-5-29
+ */
+public class DepartmentController extends BaseController {
+    static final DepartmentService departmentService = new DepartmentService();
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("department:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 部门json数据
+     */
+    public void jsonList() {
+        Page<Department> pgaeList = departmentService.departmentList(getPage(), getRows(), getPara("name"), getPara("pid"), getPara("id"), getPara("sidx", "viewSort"), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        setAttr("op", op);
+        if (op.equals("edit")) {
+            Department department = Department.dao.findFirst(Department.dao.getSql("department.findById"), getPara("id"));
+            setAttr("department", department);
+            render("form.html");
+        }
+        if (op.equals("add")) {
+            render("form.html");
+        }
+        if (op.equals("select")) {
+            render("select.html");
+        }
+    }
+
+    /**
+     * 添加部门
+     */
+    @RequiresPermissions("department:add")
+    @Before(DepartmentValidator.class)
+    public void add() {
+        Department department = getModel(Department.class, "", true);
+        department.setOpen("true");
+        department.save();
+        renderSuccess();
+    }
+
+    /**
+     * 编辑部门
+     */
+    @RequiresPermissions("department:edit")
+    @Before(DepartmentValidator.class)
+    public void edit() {
+        getModel(Department.class, "", true).update();
+        renderSuccess();
+    }
+
+    /**
+     * 删除部门
+     */
+    @RequiresPermissions("department:delete")
+    public void delete() {
+        String ids = getPara("ids");
+        Db.update("delete from sys_department where id in(" + ids + ")");
+        renderSuccess();
+    }
+
+    /**
+     * 树型菜单json数据
+     */
+    public void getTreeJson() {
+        List<Department> department_list = departmentService.getDepartmentList();
+        renderJson(department_list);
+    }
+}

+ 57 - 0
src/main/java/com/lsw/controller/admin/system/department/DepartmentService.java

@@ -0,0 +1,57 @@
+package com.lsw.controller.admin.system.department;
+
+import com.jfinal.kit.Kv;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.SqlPara;
+import com.lsw.model.Department;
+
+import java.util.List;
+
+/**
+ * Created by Administrator on 2017/5/23.
+ */
+public class DepartmentService {
+    private static final Department dao = new Department().dao();
+
+    /**
+     * 查询菜单信息
+     *
+     * @param id 菜单id
+     * @return
+     */
+    /*public Menu selectById(int id) {
+        return dao.findFirst(dao.getSql("menu.selectById"), id);
+    }*/
+
+    /**
+     * 获取所有部门列表
+     *
+     * @return
+     */
+    public List<Department> getDepartmentList() {
+        return dao.find(dao.getSql("department.getDepartmentList"));
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param page 当前页
+     * @param row  分页条数
+     * @param name 查询关键字
+     * @param pid  父部门id
+     * @param id
+     * @param sidx 排序字段
+     * @param sord 排序方式 asc|desc
+     * @return
+     */
+    public Page<Department> departmentList(int page, int row, String name, String pid, String id, String sidx, String sord) {
+        Kv kv = Kv.create();
+        kv.set("name", name);
+        kv.set("pId", pid);
+        kv.set("id", id);
+        kv.set("sidx", sidx);
+        kv.set("sord", sord);
+        SqlPara para = dao.getSqlPara("department.selectByPage", kv);
+        return dao.paginate(page, row, para);
+    }
+}

+ 14 - 0
src/main/java/com/lsw/controller/admin/system/department/DepartmentValidator.java

@@ -0,0 +1,14 @@
+package com.lsw.controller.admin.system.department;
+
+import com.jfinal.core.Controller;
+import com.lsw.base.BaseValidator;
+
+public class DepartmentValidator extends BaseValidator {
+
+    @Override
+    protected void validate(Controller c) {
+        validateRequiredString("departmentName", "msg", "部门名称不能为空");
+        validateString("departmentName",2,10,"msg","名称长度2-10个字符");
+        validateRequiredString("number", "msg", "部门编号不能为空");
+    }
+}

+ 151 - 0
src/main/java/com/lsw/controller/admin/system/file/FileController.java

@@ -0,0 +1,151 @@
+package com.lsw.controller.admin.system.file;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Duang;
+import com.jfinal.kit.PathKit;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.FileUtil;
+import com.lsw.controller.admin.system.log.operation.OlogService;
+import com.lsw.model.Department;
+import com.lsw.model.File;
+import com.lsw.shiro.tag.ShiroTag;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * 文件管理
+ */
+public class FileController extends BaseController {
+
+
+    /**
+     * 管理页面
+     */
+    public void list() {
+        List<Department>list=Department.dao.find("SELECT departmentName FROM sys_department");
+        setAttr("d_list",list);
+        render("list.html");
+    }
+
+    /**
+     * 文件json数据
+     */
+    public void jsonList() {
+        Page<File> pgaeList = File.dao.jsonList(getPage(), getRows(), getPara("name"), getPara("fileType"),getPara("department"),getParaToInt("isDelete", 0),getParaToInt("isShare", 0), getMinTime(), getMaxTime(), getSidx(), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        if (op.equals("add")) {
+            render("form.html");
+        }
+        if (op.equals("share")) {
+            File file = File.dao.findById(getPara("id"));
+            setAttr("file", file);
+            render("share.html");
+        }
+        if (op.equals("recycling")) {
+            render("recycling.html");
+        }
+        if (op.equals("share_list")) {
+            render("share_list.html");
+        }
+    }
+
+    /**
+     * 查看文件
+     */
+    public void look() {
+        File file = File.dao.findById(getPara("id"));
+        setAttr("file", file);
+        render("look.html");
+    }
+
+    @Before(FileValidator.class)
+    public void upload() {
+        File file = getAttr("file");
+        file.setUserId(ShiroTag.getUser().getId());
+        file.save();
+        Duang.duang(OlogService.class).addLog(ShiroTag.getUser().getId(), "上传文件", ShiroTag.getUser().getRealName()+"上传了"+file.getFileName());
+        renderSuccess();
+    }
+
+    public void validate(){
+        if(getPara("code").equals(getPara("dCode"))){
+            renderSuccess();
+        }else{
+            renderError("下载码错误");
+        }
+    }
+
+    /**
+     * 下载文件
+     */
+    public void download() {
+        renderFile(new java.io.File(PathKit.getWebRootPath() + getPara("name")));
+    }
+
+    /**
+     * 分享
+     */
+    public void createShare() {
+        File file = getModel(File.class, "", true);
+        file.setIsShare(1);
+        file.setShareTime(new Date());
+        //0是公开,1是加密
+        if (StrKit.notBlank(getPara("isOpen"))) {
+            file.setIsOpen(1);
+            file.setAllowPass("" + new Random().nextInt(1000000));
+        } else {
+            file.setIsOpen(0);
+        }
+        file.update();
+        Duang.duang(OlogService.class).addLog(ShiroTag.getUser().getId(), "分享文件", ShiroTag.getUser().getRealName()+"分享了"+file.getFileName());
+        renderSuccess(file);
+    }
+    /**
+     * 取消分享
+     */
+    public void cancelShare() {
+        String ids = getPara("ids");
+        Db.update("update sys_file set isShare=0 where id in(" + ids + ")");
+        renderSuccess();
+    }
+    /**
+     * 移到到回收站
+     */
+    public void recycling() {
+        String ids = getPara("ids");
+        Db.update("update sys_file set isDelete=1 where id in(" + ids + ")");
+        renderSuccess();
+    }
+    /**
+     * 恢复文件
+     */
+    public void regain() {
+        String ids = getPara("ids");
+        Db.update("update sys_file set isDelete=0 where id in(" + ids + ")");
+        renderSuccess();
+    }
+    /**
+     * 彻底删除文件
+     */
+    public void delete() {
+        String ids = getPara("ids");
+        Db.update("delete from sys_file where id in(" + ids + ")");
+        List<File> list = File.dao.find("select filePath from sys_file where id in(" + ids + ")");
+        for (File file : list) {
+            FileUtil.deleteFile(file.getRealPath());
+        }
+        renderSuccess();
+    }
+}

+ 49 - 0
src/main/java/com/lsw/controller/admin/system/file/FileValidator.java

@@ -0,0 +1,49 @@
+package com.lsw.controller.admin.system.file;
+
+import com.jfinal.core.Controller;
+import com.jfinal.kit.HashKit;
+import com.jfinal.upload.UploadFile;
+import com.lsw.base.BaseValidator;
+import com.lsw.commons.utils.FileUtil;
+import com.lsw.model.File;
+
+import java.util.Date;
+import java.util.Random;
+
+public class FileValidator extends BaseValidator {
+    String Path = "/file/";
+    UploadFile uf = null;
+
+    @Override
+    protected void validate(Controller c) {
+        File file = new File();
+        try {
+            uf = c.getFile("file", Path);
+            //判断文件类型
+            String ft = uf.getFileName().substring(uf.getFileName().lastIndexOf("."), uf.getFileName().length());
+            if (ft.equals(".png") || ft.equals(".jpg")) {
+                file.setFileType("图片");
+            } else if (ft.equals(".doc") || ft.equals(".xlsx") || ft.equals(".pdf") || ft.equals(".docx") || ft.equals(".txt") || ft.equals(".ppt")) {
+                file.setFileType("文档");
+            } else if (ft.equals(".mp4") || ft.equals(".rmvb") || ft.equals(".wmv") || ft.equals(".avi")) {
+                file.setFileType("视频");
+            } else if (ft.equals(".mp3")) {
+                file.setFileType("音乐");
+            } else {
+                file.setFileType("其它");
+            }
+            file.setFileName(uf.getFileName());
+            file.setRealPath(uf.getUploadPath() + uf.getFileName());
+            file.setFileFlag(HashKit.md5("" + new Random().nextInt(100000)));
+            file.setFilePath("/upload/file/" + uf.getFileName());
+            file.setUploadTime(new Date());
+            file.setDCode(c.getPara("dCode"));
+            file.setFileSize(FileUtil.getPrintSize(c.getParaToLong("size")));
+            c.setAttr("file", file);
+        } catch (Exception e) {
+            String msg = e.getMessage();
+            addError("msg", msg);
+        }
+    }
+}
+    

+ 136 - 0
src/main/java/com/lsw/controller/admin/system/index/IndexController.java

@@ -0,0 +1,136 @@
+package com.lsw.controller.admin.system.index;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Clear;
+import com.jfinal.core.JFinal;
+import com.jfinal.kit.HashKit;
+import com.jfinal.kit.Kv;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.Constant;
+import com.lsw.commons.utils.IpUtil;
+import com.lsw.controller.admin.system.log.login.LlogService;
+import com.lsw.controller.admin.system.user.UserValidator;
+import com.lsw.interceptor.RoleMenuInterceptor;
+import com.lsw.model.User;
+import com.lsw.shiro.tag.ShiroTag;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authc.IncorrectCredentialsException;
+import org.apache.shiro.authc.LockedAccountException;
+import org.apache.shiro.authc.UnknownAccountException;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.crypto.hash.SimpleHash;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.SimpleByteSource;
+
+import java.net.UnknownHostException;
+
+public class IndexController extends BaseController {
+    static final IndexService indexService = new IndexService();
+    static final LlogService log = new LlogService();
+
+    public void index() {
+        redirect("/admin/main");
+    }
+
+    @Clear(RoleMenuInterceptor.class)
+    public void login() {
+        keepPara("returnUrl"); // 保持住 returnUrl 这个参数,以便在登录成功后跳转到该参数指向的页面
+        render("login.html");
+
+    }
+
+    @Clear(RoleMenuInterceptor.class)
+    public void codes() {
+        renderCaptcha();
+    }
+
+    public void main() {
+        setAttr("menu_list", indexService.menuRoleList(ShiroTag.getUser().getInt("roleId")));
+        render("index.html");
+    }
+
+    @Before(UserValidator.class)
+    @Clear(RoleMenuInterceptor.class)
+    public void doLogin() throws Exception {
+        String account = getPara("account").trim();
+        String password = getPara("password").trim();
+        boolean remember = getParaToBoolean("remember", false);
+        UsernamePasswordToken token = new UsernamePasswordToken(account, password.toCharArray());
+        Subject subject = SecurityUtils.getSubject();
+        if (remember) {
+            token.setRememberMe(true);
+        }
+        try {
+            subject.login(token);
+            log.addLog(account, IpUtil.getIpAddr(getRequest()), ShiroTag.getUser(), "登录", "登录成功");
+            renderSuccess(Kv.create().set("url", JFinal.me().getContextPath() + "/admin/main"));
+        } catch (UnknownAccountException exception) {
+            log.addLog(account, IpUtil.getIpAddr(getRequest()), null, "登录", "账户不存在");
+            renderError("账户不存在");
+        } catch (IncorrectCredentialsException exception) {
+            log.addLog(account, IpUtil.getIpAddr(getRequest()), null, "登录", "密码错误");
+            renderError("密码错误");
+        } catch (LockedAccountException exception) {
+            log.addLog(account, IpUtil.getIpAddr(getRequest()), null, "登录", "账号被锁定");
+            renderError("账号被锁定");
+        }
+    }
+
+    /**
+     * 桌面
+     *
+     * @throws UnknownHostException
+     */
+    public void welcome() throws UnknownHostException {
+        render("welcome.html");
+    }
+
+    public void view() {
+        render(getPara("op", "editInfo") + ".html");
+    }
+
+    /**
+     * 用户信息编辑
+     */
+    @Before(UserValidator.class)
+    public void editInfo() {
+        User user = getModel(User.class, "", true);
+        user.update();
+        CacheKit.remove("userCache", user.getAccount());
+        renderSuccess();
+    }
+
+    /**
+     * 修改密码
+     */
+    @Before(UserValidator.class)
+    public void editPass() {
+        String salt = HashKit.generateSaltForSha256();
+        User user = getModel(User.class, "", true);
+        user.setPassword(new SimpleHash("MD5", new SimpleByteSource(user.getPassword()), new SimpleByteSource(salt), 2).toHex());
+        user.setSalt(salt);
+        user.update();
+        CacheKit.remove(Constant.userCache, user.getAccount());
+        SecurityUtils.getSubject().logout();
+        renderSuccess();
+    }
+
+    /**
+     * 注销
+     */
+    public void exit() throws Exception {
+        System.out.println("用户:" + ShiroTag.getUser().getAccount());
+        log.addLog(ShiroTag.getUser().getAccount(), IpUtil.getIpAddr(getRequest()), ShiroTag.getUser(), "注销", "注销成功");
+        SecurityUtils.getSubject().logout();
+        redirect("/admin/login");
+    }
+
+    /**
+     * 无权限
+     */
+    public void error() {
+        renderError("没有权限!");
+    }
+
+}

+ 67 - 0
src/main/java/com/lsw/controller/admin/system/index/IndexService.java

@@ -0,0 +1,67 @@
+package com.lsw.controller.admin.system.index;
+
+import com.jfinal.aop.Duang;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.lsw.commons.utils.Constant;
+import com.lsw.controller.admin.system.menu.MenuService;
+import com.lsw.model.Menu;
+
+import java.util.List;
+
+/**
+ * Created by lishuwen on 2017/5/31.
+ */
+public class IndexService {
+
+	/**
+	 * 角色资源菜单
+	 * 
+	 * @param roleId
+	 * @return
+	 */
+	public List<Menu> menuRoleList(int roleId) {
+		List<Menu> menu_list=CacheKit.get(Constant.menuRoleCache, roleId);
+		if(null==menu_list){
+			MenuService menuService = Duang.duang(MenuService.class);
+			menu_list = menuService.getRoleMenuList(roleId, 0);
+			// 一级菜单
+			for (Menu menu1 : menu_list) {
+				List<Menu> child_list = menuService.getRoleMenuList(roleId, menu1.getId());
+				if (!child_list.isEmpty()) {
+					menu1.put("child_list", child_list);
+				}
+				// 二级菜单
+				for (Menu menu2 : child_list) {
+					List<Menu> child_list2 = menuService.getRoleMenuList(roleId, menu2.getId());
+					if (!child_list2.isEmpty()) {
+						menu2.put("child_list2", child_list2);
+					}
+					// 三级级菜单
+					for (Menu menu3 : child_list2) {
+						List<Menu> child_list3 = menuService.getRoleMenuList(roleId, menu3.getId());
+						if (!child_list3.isEmpty()) {
+							menu3.put("child_list3", child_list3);
+						}
+						// 四级级菜单
+						for (Menu menu4 : child_list3) {
+							List<Menu> child_list4 = menuService.getRoleMenuList(roleId, menu4.getId());
+							if (!child_list4.isEmpty()) {
+								menu4.put("child_list4", child_list4);
+							}
+							// 五级菜单
+							for (Menu menu5 : child_list4) {
+								List<Menu> child_list5 = menuService.getRoleMenuList(roleId, menu5.getId());
+								if (!child_list5.isEmpty()) {
+									menu5.put("child_list5", child_list5);
+								}
+							}
+						}
+
+					}
+				}
+			}
+		   CacheKit.put(Constant.menuRoleCache, roleId,menu_list);
+		}
+		return menu_list;
+	}
+}

+ 179 - 0
src/main/java/com/lsw/controller/admin/system/letter/LetterController.java

@@ -0,0 +1,179 @@
+package com.lsw.controller.admin.system.letter;
+
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.lsw.base.BaseController;
+import com.lsw.model.Letter;
+import com.lsw.model.LetterUser;
+import com.lsw.model.User;
+import com.lsw.shiro.tag.ShiroTag;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 通知(站内信)管理
+ * @time 2017-5-30
+ */
+public class LetterController extends BaseController {
+    static final LetterService letterService = new LetterService();
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("letter:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 通知json数据
+     */
+    public void jsonList() {
+        Page<Letter> pgaeList = letterService.letterList(getPage(), getRows(), getPara("name"), getSidx(), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 我的通知json数据
+     */
+    public void myLetterJson() {
+        Page<Letter> pgaeList = letterService.myLetter(getPage(), getRows(), getPara("name"), ShiroTag.getUser().getId(), getSidx(), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 选择发送对象
+     */
+    public void choice() {
+        render("choice.html");
+    }
+
+    /**
+     * 我的通知列表
+     */
+    public void my_letter() {
+        render("my_letter.html");
+    }
+
+    /**
+     * 删除我的通知
+     */
+    public void del_my() {
+        String ids = getPara("ids");
+        int row = Db.update("update sys_letter_user set state=2 where id in(" + ids + ")");
+        if (row > 0) {
+            renderSuccess();
+        } else {
+            renderError("删除失败");
+        }
+    }
+
+    /**
+     * 查看我的通知
+     */
+    public void my_letter_look() {
+        Letter letter = letterService.myLetterInfo(getParaToInt("id"));
+        if (letter.getInt("state") == 0) {
+            //改为已阅
+            Db.update("UPDATE sys_letter_user SET state=1 WHERE letterId=? AND userId=?",getParaToInt("id"),ShiroTag.getUser().getId());
+        }
+        setAttr("letter", letter);
+        render("my_letter_look.html");
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        if (op.equals("edit") || op.equals("look")) {
+            List<User> userList = letterService.getObject(getParaToInt("id"));
+            Letter letter = Letter.dao.findById(getParaToInt("id"));
+            setAttr("letter", letter);
+            setAttr("userList", userList);
+            render("edit.html");
+        }
+        setAttr("op", op);
+        render(op + ".html");
+    }
+
+    /**
+     * 添加通知
+     */
+    @RequiresPermissions("letter:add")
+    @Before({LetterValidator.class, Tx.class})
+    public void add() {
+        Letter letter = getModel(Letter.class, "", true);
+        letter.setUserId(ShiroTag.getUser().getId());
+        letter.setSendObject(getPara("sendObject", "全部"));
+        letter.setSendTime(new Date());
+        letter.save();
+        List<LetterUser> letterUserList = new ArrayList<LetterUser>();
+        //选择全部用户发送
+        if (getPara("check_type", "all").equals("all")) {
+            List<User> usersList = User.dao.find("select * from sys_user where state=0");
+            for (User user : usersList) {
+                LetterUser letterUser = new LetterUser();
+                letterUser.setUserId(user.getId());
+                letterUser.setLetterId(letter.getId());
+                letterUser.setReceivedTime(new Date());
+                letterUserList.add(letterUser);
+            }
+        } else {
+            //指定用户
+            for (String id : getPara("ids").split(",")) {
+                LetterUser letterUser = new LetterUser();
+                letterUser.setUserId(Integer.parseInt(id));
+                letterUser.setLetterId(letter.getId());
+                letterUser.setReceivedTime(new Date());
+                letterUserList.add(letterUser);
+            }
+        }
+        Db.batchSave(letterUserList, letterUserList.size());
+        renderSuccess();
+    }
+
+    /**
+     * 编辑通知
+     */
+    @RequiresPermissions("letter:edit")
+    @Before(LetterValidator.class)
+    public void edit() {
+        getModel(Letter.class, "", true).update();
+        renderSuccess();
+    }
+
+    /**
+     * 删除通知
+     */
+    @RequiresPermissions("letter:delete")
+    @Before(Tx.class)
+    public void delete() {
+        String ids = getPara("ids");
+        int row = Db.update("delete from sys_letter where id in(" + ids + ")");
+        if (row > 0) {
+            Db.update("delete from sys_letter_user where letterId in(" + ids + ")");
+            renderSuccess();
+        } else {
+            renderError("删除失败");
+        }
+    }
+
+    /**
+     * 撤回或发送
+     */
+    @RequiresPermissions("letter:repeal")
+    public void repeal() {
+        Letter letter = new Letter();
+        letter.setId(getParaToInt("id"));
+        letter.setState(getParaToInt("state"));
+        letter.update();
+        renderSuccess();
+    }
+}

+ 87 - 0
src/main/java/com/lsw/controller/admin/system/letter/LetterService.java

@@ -0,0 +1,87 @@
+package com.lsw.controller.admin.system.letter;
+
+import com.jfinal.kit.Kv;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.SqlPara;
+import com.lsw.model.Letter;
+import com.lsw.model.User;
+
+import java.util.List;
+
+/**
+ * Created by Administrator on 2017/5/23.
+ */
+public class LetterService {
+    private static final Letter dao = new Letter().dao();
+
+    /**
+     * 通过letterId获取发送对象
+     *
+     * @param letterId
+     * @return
+     */
+    public List<User> getObject(int letterId) {
+        List<User> user = User.dao.find(dao.getSql("letter.getObject"), letterId);
+        return user;
+    }
+
+    /**
+     * 阅读我的通知
+     *
+     * @param id
+     * @return
+     */
+    public Letter myLetterInfo(int id) {
+        return dao.findFirst(dao.getSql("letter.myLetterInfo"), id);
+    }
+
+    /**
+     * 我的通知
+     *
+     * @param page   当前页
+     * @param row    分页条数
+     * @param name   查询关键字
+     * @param userId 用户id
+     * @param sidx   排序字段
+     * @param sord   排序方式 asc|desc
+     * @return
+     */
+    public Page<Letter> myLetter(int page, int row, String name, int userId, String sidx, String sord) {
+        Kv kv = Kv.create();
+        kv.set("name", name);
+        kv.set("userId", userId);
+        kv.set("sidx", sidx);
+        kv.set("sord", sord);
+        SqlPara para = dao.getSqlPara("letter.myLetter", kv);
+        return dao.paginate(page, row, para);
+
+    }
+    public List<Letter> myLetter(int userId) {
+        StringBuilder sb=new StringBuilder();
+        sb.append(" SELECT l.*,u.state AS mState");
+        sb.append(" FROM tb_letter l");
+        sb.append(" LEFT JOIN tb_letter_user u ON u.letterId=l.id");
+        sb.append(" WHERE u.userId=? AND l.state=0");
+        sb.append(" order by l.sendTime desc  limit 5");
+        return dao.find(sb.toString(), userId);
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param page 当前页
+     * @param row  分页条数
+     * @param name 查询关键字
+     * @param sidx 排序字段
+     * @param sord 排序方式 asc|desc
+     * @return
+     */
+    public Page<Letter> letterList(int page, int row, String name, String sidx, String sord) {
+        Kv kv = Kv.create();
+        kv.set("name", name);
+        kv.set("sidx", sidx);
+        kv.set("sord", sord);
+        SqlPara para = dao.getSqlPara("letter.selectByPage", kv);
+        return dao.paginate(page, row, para);
+    }
+}

+ 21 - 0
src/main/java/com/lsw/controller/admin/system/letter/LetterValidator.java

@@ -0,0 +1,21 @@
+package com.lsw.controller.admin.system.letter;
+
+import com.jfinal.core.Controller;
+import com.lsw.base.BaseValidator;
+
+public class LetterValidator extends BaseValidator {
+
+    @Override
+    protected void validate(Controller c) {
+        validateRequiredString("title", "msg", "发文标题不能为空");
+        validateString("title",2,30,"msg","标题长度2-30个字符");
+        validateRequiredString("content", "msg", "至少写点内容");
+        if(getActionKey().equals("/admin/letter/add")){
+            validateRequiredString("check_type", "msg", "请选择发送对象");
+            if(c.getPara("check_type").equals("choice")){
+                validateRequiredString("ids", "msg", "请选择发送对象");
+            }
+        }
+
+    }
+}

+ 50 - 0
src/main/java/com/lsw/controller/admin/system/log/login/LlogController.java

@@ -0,0 +1,50 @@
+package com.lsw.controller.admin.system.log.login;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.model.LoginLog;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+/**
+ * @author 李书文
+ * @description 登录日志
+ * @time 2017-5-29
+ */
+public class LlogController extends BaseController {
+    static final LlogService logService=new LlogService();
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("login_log:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 获取登录日志json数据
+     */
+    public void jsonList() {
+        Page<LoginLog> pgaeList = logService.logList(getPage(), getRows(),getPara("name"),getMinTime(),getMaxTime());
+        renderJson(getPage(pgaeList));
+    }
+    /**
+     * 查看日志
+     */
+    @RequiresPermissions("login_log:look")
+    public void view(){
+        LoginLog log=LoginLog.dao.findFirst(Db.getSql("log.selectLoginLogById"),getPara("id"));
+        setAttr("log",log);
+        render("look.html");
+    }
+
+    /**
+     * 删除登录日志
+     */
+    @RequiresPermissions("login_log:delete")
+    public void delete() {
+        String ids = getPara("ids");
+        Db.update("delete from sys_login_log where id in(" + ids + ")");
+        renderSuccess();
+    }
+}

+ 53 - 0
src/main/java/com/lsw/controller/admin/system/log/login/LlogService.java

@@ -0,0 +1,53 @@
+package com.lsw.controller.admin.system.log.login;
+
+import com.jfinal.kit.Kv;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.LoginLog;
+import com.lsw.model.User;
+
+import java.util.Date;
+
+/**
+ * Created by lishuwen on 2017/6/3.
+ */
+public class LlogService {
+    private static final LoginLog dao = new LoginLog();
+    /**
+     * 添加登录日志
+     *
+     * @param account 账号
+     * @param ip    公网ip地址
+     * @param user    操作人
+     * @param op      操作
+     * @param remark  备注
+     * @throws Exception
+     */
+    public void addLog(String account,String ip, User user, String op, String remark) throws Exception {
+        LoginLog log = new LoginLog();
+        log.setAccount(account);
+        log.setUserId(user == null ? 0 : user.getId());
+        log.setOperation(op);
+        //Map<String, Object> ipInfo = IpUtil.getAddress(ip);
+        //log.setIp(ipInfo.get("ip") + "," + ipInfo.get("region") + " " + ipInfo.get("city") + " " + ipInfo.get("isp"));
+        log.setIp(ip);
+        log.setCreateDate(new Date());
+        log.setRemark(remark);
+        log.save();
+    }
+
+    /**
+     * @param page 当前页
+     * @param row  分页条数
+     * @param name 搜索关键字
+     * @param min  开始日期
+     * @param max  结束日期
+     * @return
+     */
+    public Page<LoginLog> logList(int page, int row, String name, String min, String max) {
+        Kv kv = Kv.create();
+        kv.set("name", name);
+        kv.set("min", min);
+        kv.set("max", max);
+        return dao.paginate(page, row, dao.getSqlPara("log.loginLog", kv));
+    }
+}

+ 52 - 0
src/main/java/com/lsw/controller/admin/system/log/operation/OlogController.java

@@ -0,0 +1,52 @@
+package com.lsw.controller.admin.system.log.operation;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.model.OperationLog;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+/**
+ * @author 李书文
+ * @description 操作日志
+ * @time 2017-5-29
+ */
+public class OlogController extends BaseController {
+    static final OlogService logService = new OlogService();
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("operation:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 获取操作日志json数据
+     */
+    public void jsonList() {
+        Page<OperationLog> pgaeList = logService.logList(getPage(), getRows(), getPara("name"), getMinTime(), getMaxTime());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 查看日志
+     */
+    @RequiresPermissions("operation:look")
+    public void view() {
+        OperationLog log = OperationLog.dao.findFirst(Db.getSql("log.selectOperationLogById"),getPara("id"));
+        setAttr("log", log);
+        render("look.html");
+    }
+
+    /**
+     * 删除操作日志
+     */
+    @RequiresPermissions("operation:delete")
+    public void delete() {
+        String ids = getPara("ids");
+        Db.update("delete from sys_operation_log where id in(" + ids + ")");
+        renderSuccess();
+    }
+}

+ 45 - 0
src/main/java/com/lsw/controller/admin/system/log/operation/OlogService.java

@@ -0,0 +1,45 @@
+package com.lsw.controller.admin.system.log.operation;
+
+import com.jfinal.kit.Kv;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.OperationLog;
+
+import java.util.Date;
+
+/**
+ * Created by lishuwen on 2017/6/3.
+ */
+public class OlogService {
+    private static final OperationLog dao = new OperationLog();
+    /**
+     * 添加操作日志
+     *
+     * @param userId 操作人Id
+     * @param op     操作
+     * @param remark 备注
+     */
+    public void addLog(int userId, String op, String remark) {
+        OperationLog log=new OperationLog();
+        log.setUserId(userId);
+        log.setOperation(op);
+        log.setCreateDate(new Date());
+        log.setRemark(remark);
+        log.save();
+    }
+
+    /**
+     * @param page 当前页
+     * @param row  分页条数
+     * @param name 搜索关键字
+     * @param min  开始日期
+     * @param max  结束日期
+     * @return
+     */
+    public Page<OperationLog> logList(int page, int row, String name, String min, String max) {
+        Kv kv = Kv.create();
+        kv.set("name", name);
+        kv.set("min", min);
+        kv.set("max", max);
+        return dao.paginate(page, row, dao.getSqlPara("log.operationLog", kv));
+    }
+}

+ 125 - 0
src/main/java/com/lsw/controller/admin/system/menu/MenuController.java

@@ -0,0 +1,125 @@
+package com.lsw.controller.admin.system.menu;
+
+import com.jfinal.aop.Before;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.Constant;
+import com.lsw.model.Menu;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 菜单管理
+ * @time 2017-5-30
+ */
+public class MenuController extends BaseController {
+    static final MenuService menuService = new MenuService();
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("menu:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 菜单json数据
+     */
+    public void jsonList() {
+        Page<Menu> pgaeList = menuService.menuList(getPage(), getRows(), getPara("name"), getPara("pid"), getPara("id"), getPara("sidx", "viewSort"), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 选择图标
+     */
+    public void icon() {
+        render("icon.html");
+    }
+
+    /**
+     * 选择上级菜单
+     */
+    public void select() {
+        render("select.html");
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        //上级菜单
+        List<Menu> menu_list = menuService.superiorMenuList();
+        if (op.equals("edit")) {
+            Menu menu = menuService.selectById(getParaToInt("id"));
+            setAttr("menu", menu);
+        }
+        setAttr("menu_list", menu_list);
+        setAttr("op", op);
+        render("form.html");
+    }
+
+    /**
+     * 添加菜单
+     */
+    @RequiresPermissions("menu:add")
+    @Before(MenuValidator.class)
+    public void add() {
+        Menu menu = getModel(Menu.class, "", true);
+        menu.setOpen("true");
+        if (menu.getPId() == 0) {
+            menu.setPId(0);
+        }
+        menu.save();
+        renderSuccess();
+    }
+
+    /**
+     * 编辑菜单
+     */
+    @RequiresPermissions("menu:edit")
+    @Before(MenuValidator.class)
+    public void edit() {
+        getModel(Menu.class, "", true).update();
+        CacheKit.removeAll(Constant.menuRoleCache);
+        renderSuccess();
+    }
+
+    /**
+     * 删除菜单
+     */
+    @RequiresPermissions("menu:delete")
+    public void delete() {
+        String ids = getPara("ids");
+        int row = Db.update("delete from sys_menu where id in(" + ids + ")");
+        if (row > 0) {
+            //删除相应的资源权限
+            Db.update("delete from sys_menu_role where menuId in(" + ids + ")");
+            //删除相应的子菜单
+            boolean child = menuService.hasChild(ids);
+            if (child) {
+                Db.update("delete from sys_menu where pId in(" + ids + ")");
+            }
+            //更新授权资源缓存
+            CacheKit.removeAll(Constant.menuRoleCache);
+            renderSuccess();
+        } else {
+            renderError("删除失败");
+        }
+    }
+
+    /**
+     * 树型菜单json数据
+     */
+    public void getTreeJson() {
+        List<Menu> menu_list = menuService.getMenuList();
+        renderJson(menu_list);
+    }
+}

+ 141 - 0
src/main/java/com/lsw/controller/admin/system/menu/MenuService.java

@@ -0,0 +1,141 @@
+package com.lsw.controller.admin.system.menu;
+
+import com.jfinal.kit.Kv;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.SqlPara;
+import com.lsw.commons.utils.Constant;
+import com.lsw.model.Menu;
+import com.lsw.model.MenuRole;
+
+import java.util.List;
+
+/**
+ * Created by Administrator on 2017/5/23.
+ */
+public class MenuService {
+    private static final Menu dao = new Menu().dao();
+
+    /**
+     * 查询该菜单是否有子菜单
+     *
+     * @param pid
+     * @return
+     */
+    public boolean hasChild(String pid) {
+        SqlPara para=dao.getSqlPara("menu.hasChild",Kv.by("pid",pid));
+        List<Menu> list = dao.find(para);
+        System.out.println("list:"+list.size());
+        return list.size() == 0 ? false : true;
+    }
+
+    /**
+     * 查询菜单资源列表
+     *
+     * @return
+     */
+    public List<Menu> getMenuList() {
+        List<Menu> list = dao.find(dao.getSql("menu.getMenuList"));
+        return list;
+    }
+
+    /**
+     * 通过获取xx/list的url查询菜单进而通过菜单的pid查询该菜单下面的授权按钮
+     *
+     * @param url
+     * @return
+     */
+    public Menu getMenuByUrl(String url) {
+        return dao.findFirstByCache(Constant.urlCache, url, dao.getSql("menu.getMenuByUrl"), url);
+    }
+
+    /**
+     * 查询角色的菜单资源列表
+     *
+     * @param roleId 角色Id
+     * @return
+     */
+    public List<MenuRole> getMenuRoleList(int roleId) {
+        List<MenuRole> list = MenuRole.dao.find(dao.getSql("menu.getMenuRoleList"), roleId);
+        return list;
+    }
+
+    /**
+     * 查询角色的授权列表
+     *
+     * @param roleId 角色Id
+     * @return
+     */
+    public List<Menu> getAuthorizationList(int roleId) {
+        List<Menu> list = dao.find(dao.getSql("menu.getAuthorizationList"), roleId);
+        return list;
+    }
+
+    /**
+     * 获取角色资源菜单
+     *
+     * @param roleId 角色id
+     * @param pid    父菜单id
+     * @return
+     */
+    public List<Menu> getRoleMenuList(int roleId, int pid) {
+        SqlPara para = dao.getSqlPara("menu.getRoleMenuList", Kv.create().set("roleId", roleId).set("pid", pid).set("type", 0));
+        List<Menu> list = dao.find(para);
+        return list;
+    }
+
+    /**
+     * 获取角色权限按钮
+     *
+     * @param roleId 角色id
+     * @param pid    父菜单id
+     * @return
+     */
+    public List<Menu> getRoleButtonList(int roleId, int pid) {
+        SqlPara para = dao.getSqlPara("menu.getRoleMenuList", Kv.create().set("roleId", roleId).set("pid", pid).set("type", 1));
+        List<Menu> list = dao.find(para.getSql(), para.getPara());
+        return list;
+    }
+
+    /**
+     * 查询菜单信息
+     *
+     * @param id 菜单id
+     * @return
+     */
+    public Menu selectById(int id) {
+        return dao.findFirst(dao.getSql("menu.selectById"), id);
+    }
+
+    /**
+     * 查询上级菜单列表
+     *
+     * @return
+     */
+    public List<Menu> superiorMenuList() {
+        return dao.find(dao.getSql("menu.superiorMenuList"));
+    }
+
+    /**
+     * 分页查询
+     *
+     * @param page 当前页
+     * @param row  分页条数
+     * @param name 查询关键字
+     * @param pid  父菜单id
+     * @param id
+     * @param sidx 排序字段
+     * @param sord 排序方式 asc|desc
+     * @return
+     */
+    public Page<Menu> menuList(int page, int row, String name, String pid, String id, String sidx, String sord) {
+        Kv cond = Kv.create();
+        if (StrKit.notBlank(name)) {
+            cond.set("m.menuName like", "%" + name + "%");
+        }
+        cond.set("m.pId=", pid);
+        cond.set("m.id=", id);
+        SqlPara para = dao.getSqlPara("menu.selectByPage", Kv.create().set("cond", cond).set("sidx", sidx).set("sord", sord));
+        return dao.paginate(page, row, para);
+    }
+}

+ 14 - 0
src/main/java/com/lsw/controller/admin/system/menu/MenuValidator.java

@@ -0,0 +1,14 @@
+package com.lsw.controller.admin.system.menu;
+
+import com.jfinal.core.Controller;
+import com.lsw.base.BaseValidator;
+
+public class MenuValidator extends BaseValidator {
+
+    @Override
+    protected void validate(Controller c) {
+        validateRequiredString("menuName", "msg", "菜单名称不能为空");
+        validateString("menuName",2,10,"msg","菜单长度2-10个字符");
+        validateRequiredString("menuName", "msg", "菜单名称不能为空");
+    }
+}

+ 5 - 0
src/main/java/com/lsw/controller/admin/system/package-info.java

@@ -0,0 +1,5 @@
+/**
+ * Created by lishuwen on 2018/9/21.
+ * 这里存放系统相关的代码例如登录
+ */
+package com.lsw.controller.admin.system;

+ 151 - 0
src/main/java/com/lsw/controller/admin/system/role/RoleController.java

@@ -0,0 +1,151 @@
+package com.lsw.controller.admin.system.role;
+
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.Constant;
+import com.lsw.controller.admin.system.menu.MenuService;
+import com.lsw.controller.admin.system.user.UserService;
+import com.lsw.model.Menu;
+import com.lsw.model.MenuRole;
+import com.lsw.model.Role;
+import com.lsw.model.User;
+import com.lsw.shiro.tag.ShiroTag;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 角色管理
+ * @time 2017-5-29
+ */
+public class RoleController extends BaseController {
+    static final RoleService roleService = new RoleService();
+    static final MenuService menuService = new MenuService();
+    static final UserService userService = new UserService();
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("role:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 获取角色json数据
+     */
+    public void jsonList() {
+        Page<Role> pgaeList = roleService.roleList(getPage(), getRows(), getPara("name"), getSidx(), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        if (op.equals("edit")) {
+            Role role = Role.dao.findById(getPara("id"));
+            setAttr("role", role);
+        }
+        // 授权页面
+        if (op.equals("authorization")) {
+            List<Menu> menu_list = menuService.getMenuList();
+            List<MenuRole> role_list = menuService.getMenuRoleList(getParaToInt("id"));
+            setAttr("roleId", getParaToInt("id"));
+            setAttr("menu_list", menu_list);
+            setAttr("role_list", role_list);
+        }
+        setAttr("op", op);
+        render(op.equals("add") || op.equals("edit") ? "form.html" : "authorization.html");
+    }
+
+    /**
+     * 添加角色
+     */
+    @RequiresPermissions("role:add")
+    @Before(RoleValidator.class)
+    public void add() {
+        Role role = getModel(Role.class, "", true);
+        boolean isExit = roleService.findByName(role.getRoleName());
+        if (isExit) {
+            role.setPushTime(new Date());
+            role.save();
+            renderSuccess();
+        } else {
+            renderError("角色已存在");
+        }
+    }
+
+    /**
+     * 编辑角色
+     */
+    @RequiresPermissions("role:edit")
+    @Before(RoleValidator.class)
+    public void edit() {
+        Role role = getModel(Role.class, "", true);
+        role.update();
+        int oldEnable = getParaToInt("oldEnable", 0);
+        //启用或关闭角色更新相应授权缓存和角色资源菜单缓存
+        if (oldEnable != role.getEnable()) {
+            List<User> userList = userService.getUserListByRoleId(role.getId());
+            for (User user : userList) {
+                ShiroTag.getDbRealm().clearCacheAuthor(user.getAccount());
+            }
+            CacheKit.remove(Constant.menuRoleCache, role.getId());
+        }
+        renderSuccess();
+    }
+
+    /**
+     * 角色授权
+     */
+    @RequiresPermissions("role:authorization")
+    public void authorization() {
+        String json = getPara("list");
+        int roleId = getParaToInt("roleId");
+        Db.update("delete  from sys_menu_role where roleId=?", roleId);
+        List<MenuRole> list = JSONObject.parseArray(json, MenuRole.class);
+        Db.batchSave(list, list.size());
+        List<User> userList = userService.getUserListByRoleId(roleId);
+        // 更新相关用户的授权信息和资源菜单
+        for (User user : userList) {
+            ShiroTag.getDbRealm().clearCacheAuthor(user.getAccount());
+        }
+        CacheKit.remove(Constant.menuRoleCache, roleId);
+        renderSuccess();
+    }
+
+    /**
+     * 删除角色
+     */
+    @RequiresPermissions("role:delete")
+    public void delete() {
+        String ids = getPara("ids");
+        for (String id : ids.split(",")) {
+            if (Integer.parseInt(id) == 19) {
+                renderError("超级管理员不允许删除!");
+                return;
+            }
+        }
+        //如果该角色下面有用户提示删除此角色下的用户
+        long counts = Db.queryLong("select count(userId) from sys_user_role ur left join sys_role r ON r.id=ur.roleId where r.id in(" + ids + ")");
+        if (counts > 0) {
+            renderError("删除失败,请先删除此角色下的用户!");
+            return;
+        }
+        //删除角色表的角色
+        Db.update("delete from sys_role where id in(" + ids + ")");
+        //删除用户角色表的角色
+        Db.update("delete from sys_user_role where roleId in(" + ids + ")");
+        //更新授权缓存
+        ShiroTag.getDbRealm().clearAllAuthorizationCache();
+        renderSuccess();
+    }
+}

+ 58 - 0
src/main/java/com/lsw/controller/admin/system/role/RoleService.java

@@ -0,0 +1,58 @@
+package com.lsw.controller.admin.system.role;
+
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.Role;
+
+/**
+ * Created by Administrator on 2017/5/23.
+ */
+public class RoleService {
+    private static final Role dao = new Role().dao();
+
+    /**
+     * 分页查询
+     *
+     * @param page 当前页
+     * @param row  分页条数
+     * @param name 查询关键字
+     * @param sidx 排序字段
+     * @param sord 排序方式 asc|desc
+     * @return
+     */
+    public Page<Role> roleList(int page, int row, String name, String sidx, String sord) {
+        StringBuilder sb = new StringBuilder();
+        String select = "select *";
+        sb.append(" from sys_role");
+        if (StrKit.notBlank(name)){
+        sb.append(" where roleName like '%" + name + "%'");
+        }
+        sb.append(" ORDER BY " + sidx + " " + sord);
+        return dao.paginate(page, row, select, sb.toString());
+    }
+
+    /**
+     * 查询角色是否存在
+     *
+     * @param name 角色名称
+     * @return true|false
+     */
+    public boolean findByName(String name) {
+        Role role = dao.findFirst("select * from sys_role where roleName=?", name);
+        if (role == null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 通过账号获取角色
+     * @param account
+     * @return
+     */
+    public Role  getRoleByAccount(String account){
+     return dao.findFirst(dao.getSql("role.getRoleByAccount"),account);
+
+    }
+}

+ 15 - 0
src/main/java/com/lsw/controller/admin/system/role/RoleValidator.java

@@ -0,0 +1,15 @@
+package com.lsw.controller.admin.system.role;
+
+import com.jfinal.core.Controller;
+import com.lsw.base.BaseValidator;
+
+public class RoleValidator extends BaseValidator {
+
+    @Override
+    protected void validate(Controller c) {
+        validateRequiredString("roleName", "msg", "角色不能为空");
+        validateString("roleName", 2,10, "msg", "角色长度2-10个长度");
+        validateRequiredString("note", "msg", "描述不能为空");
+        validateString("note", 2,50, "msg", "描述长度2-50个长度");
+    }
+}

+ 67 - 0
src/main/java/com/lsw/controller/admin/system/upload/UploadController.java

@@ -0,0 +1,67 @@
+package com.lsw.controller.admin.system.upload;
+
+import com.jfinal.kit.PathKit;
+import com.jfinal.kit.PropKit;
+import com.jfinal.kit.Ret;
+import com.jfinal.upload.UploadFile;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.Constant;
+import com.lsw.commons.utils.ImageKit;
+import com.lsw.commons.utils.ImageZipUtil;
+
+import java.io.File;
+import java.util.Random;
+
+/**
+ * @author 李书文
+ * @description 百度富文本图片上传
+ * @time 2017-8-23
+ */
+public class UploadController extends BaseController {
+    String Path = "/images/ueditor/";
+
+    public void index() {
+        if ("config".equals(getPara("action"))) {
+            render("/static/third-party/ueditor/jsp/config.json");
+            return;
+        }
+        if (getPara("action").equals("uploadimage")) {
+            uploadImage();
+        }
+    }
+
+    public void uploadImage() {
+        UploadFile uf = null;
+        String imgName = System.currentTimeMillis() + new Random().nextInt(10000) + ".jpg";
+        try {
+            uf = getFile("upfile", Path, Constant.maxPostSize);
+            uf.getFile().renameTo(new File(PathKit.getWebRootPath() + "/upload" + Path + imgName));
+            ImageZipUtil.zipImageFile(new File(uf.getUploadPath() + imgName), new File(PathKit.getWebRootPath() + "/upload" + Path + imgName));
+            if (ImageKit.notImageExtName(uf.getFileName())) {
+                uf.getFile().delete();
+                renderJson(Ret.fail("state", "只支持图片类型:gif、jpg、jpeg、png"));
+                return;
+            }
+            Ret ret = Ret.create("state", "SUCCESS")  //下面这几个都是必须返回给ueditor的数据
+                    .set("url", PropKit.get("host")+"/upload" + Path + imgName)  //文件上传后的路径
+                    .set("title", uf.getFileName())  //文件名称
+                    .set("original", uf.getOriginalFileName())
+                    .set("type", "." + uf.getFileName().split("\\."))
+                    .set("size", uf.getFile().length());
+            renderJson(ret);
+        } catch (Exception e) {
+            String msg = e.getMessage();
+            if (msg != null) {
+                if (msg.indexOf("exceeds") != -1) {
+                    renderJson(Ret.fail("state", "大小超出20M限制"));
+                    return;
+                }
+                if (uf != null) {
+                    uf.getFile().delete();
+                }
+                renderJson(Ret.fail("state", msg));
+            }
+        }
+    }
+
+}

+ 169 - 0
src/main/java/com/lsw/controller/admin/system/user/UserController.java

@@ -0,0 +1,169 @@
+package com.lsw.controller.admin.system.user;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Duang;
+import com.jfinal.kit.HashKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.Constant;
+import com.lsw.controller.admin.system.department.DepartmentService;
+import com.lsw.model.Department;
+import com.lsw.model.Role;
+import com.lsw.model.User;
+import com.lsw.model.UserRole;
+import com.lsw.shiro.tag.ShiroTag;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.apache.shiro.crypto.hash.SimpleHash;
+import org.apache.shiro.util.SimpleByteSource;
+
+import java.util.Date;
+import java.util.List;
+
+public class UserController extends BaseController {
+    static final UserService userService = new UserService();
+
+    /**
+     * 用户管理
+     */
+    @RequiresPermissions("user:list")
+    public void list() {
+        render("list.html");
+    }
+
+    public void jsonList() {
+        Page<User> pgaeList = userService.userList(getPage(), getRows(),getPara("field"),getPara("val"),getPara("depId"),getPara("pId"),getSidx(), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        //角色
+        List<Role> role_list = Role.dao.find("select * from sys_role");
+        //部门
+        List<Department>department_list= Duang.duang(DepartmentService.class).getDepartmentList();
+        if (op.equals("edit")) {
+            User user = userService.getUserById(getParaToInt("id"));
+            setAttr("userInfo", user);
+        }
+        setAttr("op", op);
+        setAttr("role_list", role_list);
+        setAttr("department_list", department_list);
+        render("form.html");
+    }
+
+    /**
+     * 新增用户
+     */
+    @RequiresPermissions("user:add")
+    @Before({UserValidator.class,Tx.class})
+    public void add() {
+        User user = getModel(User.class, "", true);
+        boolean isExit = userService.findByAccount(user.getAccount());
+        if (isExit) {
+            String salt = HashKit.generateSaltForSha256();
+            //密码加密
+            user.setPassword(new SimpleHash("MD5", new SimpleByteSource(user.getPassword()), new SimpleByteSource(salt), 2).toHex());
+            user.setSalt(salt);
+            user.setReleaseTime(new Date());
+            user.save();
+            //同时新增对应的用户角色
+            new UserRole().set("userId", user.getId()).set("roleId", getPara("roleId")).save();
+            renderSuccess();
+        } else {
+            renderError("用户已存在");
+        }
+    }
+
+    /**
+     * 编辑用户
+     */
+    @RequiresPermissions("user:edit")
+    @Before({UserValidator.class,Tx.class})
+    public void edit() {
+        User user = getModel(User.class, "", true);
+        user.update();
+        int oldRoleId = getParaToInt("oldRoleId", 0);
+        int roleId = getParaToInt("roleId",0);
+        //更换角色更新它授权缓存和资源菜单
+        if (oldRoleId != roleId) {
+            if(user.getAccount().equals(ShiroTag.getUser().getAccount())){
+                renderError("不能更换自己的角色!");
+                return;
+            }
+            Db.update(" update sys_user_role set roleId=? where userId=? and roleId=?", roleId, user.getId(), oldRoleId);
+            CacheKit.remove(Constant.menuRoleCache, oldRoleId);
+        }
+        CacheKit.remove(Constant.userCache, user.getAccount());
+        ShiroTag.getDbRealm().clearCacheAuthor(user.getAccount());
+        renderSuccess();
+    }
+
+    @RequiresPermissions("user:delete")
+    @Before(Tx.class)
+    public void delete() {
+        String ids = getPara("ids");
+            //清除对应用户授权及信息
+            for (String id : ids.split(",")) {
+                User user = User.dao.findById(id);
+                if(user.getAccount().equals(ShiroTag.getUser().getAccount())){
+                    renderError("不能删除自己!");
+                    return;
+                }
+                ShiroTag.getDbRealm().clearCacheAuthen(user.getAccount());
+                ShiroTag.getDbRealm().clearCacheAuthor(user.getAccount());
+                CacheKit.remove(Constant.userCache, user.getAccount());
+            }
+            //删除用户及对应的用户角色
+            Db.update("delete from sys_user where id in(" + ids + ")");
+            Db.update("delete from sys_user_role where userId in(" + ids + ")");
+            renderSuccess();
+    }
+
+    /**
+     * 密码重置恢复到123456
+     */
+    @RequiresPermissions("user:reset")
+    public void reset(){
+        User user=new User();
+        user.setId(getParaToInt("id"));
+        String salt = HashKit.generateSaltForSha256();
+        user.setPassword(new SimpleHash("MD5", new SimpleByteSource("123456"), new SimpleByteSource(salt), 2).toHex());
+        user.setSalt(salt);
+        user.update();
+        CacheKit.remove(Constant.userCache, getPara("account"));
+        renderSuccess();
+    }
+    /**
+     * 锁定用户
+     */
+    @RequiresPermissions("user:lock")
+    public void lock(){
+        User user=new User();
+        user.setId(getParaToInt("id"));
+        user.setState(1);
+        user.update();
+        ShiroTag.getDbRealm().clearCacheAuthen(getPara("account"));
+        ShiroTag.getDbRealm().clearCacheAuthor(getPara("account"));
+        CacheKit.remove(Constant.userCache, getPara("account"));
+        renderSuccess();
+    }
+    /**
+     * 启用用户
+     */
+    @RequiresPermissions("user:enable")
+    public void enable(){
+        User user=new User();
+        user.setId(getParaToInt("id"));
+        user.setState(0);
+        user.update();
+        ShiroTag.getDbRealm().clearCacheAuthor(getPara("account"));
+        renderSuccess();
+    }
+
+}

+ 88 - 0
src/main/java/com/lsw/controller/admin/system/user/UserService.java

@@ -0,0 +1,88 @@
+package com.lsw.controller.admin.system.user;
+
+import com.jfinal.kit.Kv;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.jfinal.plugin.activerecord.SqlPara;
+import com.lsw.commons.utils.Constant;
+import com.lsw.model.User;
+
+import java.util.List;
+
+public class UserService {
+    public static final UserService service = new UserService();
+    private final User dao = new User().dao();
+    /**
+     * 检查用户
+     * @param account
+     * @return
+     */
+    public User login(String account){
+        return dao.findFirst("select * from sys_user where account=? limit 1", account);
+    }
+
+    /**
+     * 通过角色获取用户用户更新角色授权
+     * @param roleId
+     * @return
+     */
+    public List<User>getUserListByRoleId(int roleId){
+        return  dao.find(dao.getSql("user.getUserListByRoleId"),roleId);
+    }
+
+    /**
+     * 查询用户是否存在
+     *
+     * @param name 用户名
+     * @return true|false
+     */
+    public boolean findByAccount(String name) {
+        User user = User.dao.findFirst("select * from sys_user where account=?", name);
+        if (user == null) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 获取超级管理员的电话(用于用户预约的时候通知管理员)
+     * @return
+     */
+    public List<User>getAdminPhones(){
+        return dao.find(dao.getSql("user.getAdminPhones"));
+    }
+
+    public User getUserById(int id) {
+        return dao.findFirst(dao.getSql("user.getUserById"), id);
+    }
+    public User getUserByAccount(String account) {
+        return dao.findFirstByCache(Constant.userCache,account,dao.getSql("user.getUserByAccount"), account);
+    }
+    
+    /**
+     * 分页查询
+     *
+     * @param page 当前页
+     * @param row  分页条数
+     * @param field 查询条件
+     * @param val 输入查询值
+     * @param depId 部门Id
+     * @param pId   上级部门id
+     * @param sidx 排序字段
+     * @param sord 排序方式 asc|desc
+     * @return
+     */
+    public Page<User> userList(int page, int row, String field,String val,String depId,String pId ,String sidx, String sord) {
+        Kv cond = Kv.create();
+        if(StrKit.notBlank(val)){
+            cond.set("AND u."+field+" LIKE", "%"+val+"%");
+        }
+        cond.set("AND u.depId=", depId);
+        cond.set("AND d.pId=", pId);
+        cond.set("OR d.id=", pId);
+        SqlPara para = dao.getSqlPara("user.selectByPage", Kv.create().set("cond",cond).set("sidx",sidx).set("sord",sord));
+        return dao.paginate(page, row, para);
+    }
+
+}

+ 43 - 0
src/main/java/com/lsw/controller/admin/system/user/UserValidator.java

@@ -0,0 +1,43 @@
+package com.lsw.controller.admin.system.user;
+
+import com.jfinal.core.Controller;
+import com.jfinal.kit.StrKit;
+import com.lsw.base.BaseValidator;
+
+public class UserValidator extends BaseValidator {
+
+    @Override
+    protected void validate(Controller c) {
+        validateRequiredString("account", "msg", "账号不能为空");
+        if(getActionKey().equals("/admin/doLogin")){
+            validateRequiredString("password", "msg", "密码不能为空");
+            validateRequiredString("code", "msg", "验证码不能为空");
+            validateCaptcha("code", "msg", "验证码不正确");
+        }
+        if(getActionKey().equals("/admin/user/add")){
+            validateRequiredString("account", "msg", "账号不能为空");
+            validateAccount("account","msg","输入6-20位的字母或数字");
+        	validateRequiredString("realName", "msg", "姓名不能为空");
+            validateRequiredString("password", "msg", "密码不能为空");
+            if(StrKit.notBlank(c.getPara("email"))){
+                validateEmail("email","msg","邮箱格式不正确");
+            }
+            if(StrKit.notBlank(c.getPara("phone"))){
+                validatePhone("phone","msg","手机格式不正确");
+            }
+        }
+        if(getActionKey().equals("/admin/user/edit")){
+        	validateRequiredString("realName", "msg", "姓名不能为空");
+            if(StrKit.notBlank(c.getPara("email"))){
+                validateEmail("email","msg","邮箱格式不正确");
+            }
+            if(StrKit.notBlank(c.getPara("phone"))){
+                validatePhone("phone","msg","手机格式不正确");
+            }
+        }
+        if(getActionKey().equals("/admin/editPass")){
+            validateRequiredString("password", "msg", "新密码不能为空");
+            validateEqualString(c.getPara("password"), c.getPara("again"), "msg", "两次输入不一致");
+        }
+    }
+}

+ 82 - 0
src/main/java/com/lsw/controller/admin/work/apply/ApplyController.java

@@ -0,0 +1,82 @@
+package com.lsw.controller.admin.work.apply;
+
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.model.Apply;
+import com.lsw.model.Process;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 申请单管理
+ */
+public class ApplyController extends BaseController {
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("apply:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 获取角色json数据
+     */
+    public void jsonList() {
+        Page<Apply> pgaeList = Apply.dao.jsonList(getPage(), getRows(), getPara("name"), getSidx(), getSord());
+        for (Apply apply : pgaeList.getList()) {
+            Process process = Process.dao.findFirst("select * from tb_process where pId=? and steps=?", apply.getProcessId(), apply.getSteps());
+            if(process==null){
+                apply.put("now", "结束");
+            }else{
+                apply.put("now", process.getName());
+            }
+        }
+        renderJson(getPage(pgaeList));
+    }
+
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        setAttr("op", op);
+        if (op.equals("add")) {
+            render("form.html");
+        }
+        if (op.equals("edit")) {
+            Apply apply = Apply.dao.selectById(getParaToInt("id"));
+            List<Process> step_list = Process.dao.find("select * from tb_process where pId=?", apply.getProcessId());
+            setAttr("apply", apply);
+            setAttr("now", getPara("now"));
+            setAttr("step_list", JsonKit.toJson(step_list));
+            render("form.html");
+        }
+    }
+
+
+    /**
+     * 编辑角色
+     */
+    @RequiresPermissions("apply:edit")
+    public void edit() {
+        Apply apply = getModel(Apply.class, "", true);
+        apply.update();
+        renderSuccess();
+    }
+
+    /**
+     * 删除
+     */
+    @RequiresPermissions("apply:delete")
+    public void delete() {
+        Db.update("delete from tb_apply where id in(" + getPara("ids") + ")");
+        renderSuccess();
+    }
+}

+ 79 - 0
src/main/java/com/lsw/controller/admin/work/constant/ConstantController.java

@@ -0,0 +1,79 @@
+package com.lsw.controller.admin.work.constant;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.model.Constant;
+import com.lsw.model.Role;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 平台常量管理
+ */
+public class ConstantController extends BaseController {
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("constant:list")
+    public void list() {
+        List<Constant> constant_list = Constant.dao.find("select * from tb_constant where type=0");
+        setAttr("constant_list", constant_list);
+        render("list.html");
+    }
+
+    /**
+     * 获取角色json数据
+     */
+    public void jsonList() {
+        Page<Constant> pgaeList = Constant.dao.jsonList(getPage(), getRows(), getPara("name"), getPara("type"), getSidx(), getSord());
+        renderJson(getPage(pgaeList));
+    }
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        List<Constant> constant_list = Constant.dao.find("select * from tb_constant where type=0");
+        if (op.equals("edit")) {
+            Constant constant = Constant.dao.findById(getPara("id"));
+            setAttr("constant", constant);
+        }
+        setAttr("op", op);
+        setAttr("constant_list", constant_list);
+        render(op.equals("add") || op.equals("edit") ? "form.html" : "authorization.html");
+    }
+
+    /**
+     * 添加角色
+     */
+    @RequiresPermissions("constant:add")
+    public void add() {
+        Constant constant = getModel(Constant.class, "", true);
+        constant.save();
+        renderSuccess();
+    }
+
+    /**
+     * 编辑角色
+     */
+    @RequiresPermissions("constant:edit")
+    public void edit() {
+        Constant constant = getModel(Constant.class, "", true);
+        constant.update();
+        renderSuccess();
+    }
+
+    /**
+     * 删除
+     */
+    @RequiresPermissions("constant:delete")
+    public void delete() {
+        Db.update("delete from tb_constant where id in(" + getPara("ids") + ")");
+        renderSuccess();
+    }
+}

+ 5 - 0
src/main/java/com/lsw/controller/admin/work/package-info.java

@@ -0,0 +1,5 @@
+/**
+ * Created by lishuwen on 2018/9/21.
+ * 这里存放业务逻辑代码
+ */
+package com.lsw.controller.admin.work;

+ 119 - 0
src/main/java/com/lsw/controller/admin/work/process/ProcessController.java

@@ -0,0 +1,119 @@
+package com.lsw.controller.admin.work.process;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.json.FastJson;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.base.BaseController;
+import com.lsw.model.Apply;
+import com.lsw.model.Process;
+import com.lsw.model.Role;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+import java.util.List;
+
+/**
+ * @author 李书文
+ * @description 平台常量管理
+ */
+public class ProcessController extends BaseController {
+
+    /**
+     * 管理页面
+     */
+    @RequiresPermissions("process:list")
+    public void list() {
+        render("list.html");
+    }
+
+    /**
+     * 获取流程json数据
+     */
+    public void jsonList() {
+        Page<Process> pgaeList = Process.dao.jsonList(getPage(), getRows(), getPara("name"), getSidx(), getSord());
+        for (Process p : pgaeList.getList()) {
+            System.out.println(p.getId());
+            List<Process> lists = Process.dao.find("select * from tb_process where pId=? order by id asc", p.getId());
+            p.put("lists", lists);
+
+        }
+        renderJson(getPage(pgaeList));
+    }
+
+
+    /**
+     * 视图页面
+     */
+    public void view() {
+        String op = getPara("op");
+        setAttr("op", op);
+        if (op.equals("add")) {
+            render("form.html");
+        }
+        if (op.equals("edit")) {
+            Process process = Process.dao.findById(getPara("id"));
+            List<Process> step_list = Process.dao.find("SELECT * FROM tb_process WHERE pId=?", process.getId());
+            setAttr("process", JsonKit.toJson(process));
+            setAttr("step_list", JsonKit.toJson(step_list));
+            render("form.html");
+        }
+        if (op.equals("choice")) {
+            List<Role> role_list = Role.dao.find("select * from sys_role");
+            setAttr("role_list", role_list);
+            render("choice.html");
+        }
+    }
+
+    /**
+     * 添加流程
+     */
+    @RequiresPermissions("process:add")
+    public void add() {
+        Process process = FastJson.getJson().parse(getPara("process"), Process.class);
+        process.save();
+        JSONArray step_list = JSON.parseArray(getPara("step_list"));
+        for (int i = 0; i < step_list.size(); i++) {
+            JSONObject object = step_list.getJSONObject(i);
+            Process p = new Process();
+            p.setPId(process.getId());
+            p.setName(object.getString("name"));
+            p.setSteps(i + 1);
+            p.setApproval(object.getString("approval"));
+            p.save();
+        }
+        renderSuccess();
+    }
+
+    /**
+     * 编辑流程
+     */
+    @RequiresPermissions("process:edit")
+    public void edit() {
+        Process process = FastJson.getJson().parse(getPara("process"), Process.class);
+        process.update();
+        Db.update("delete from tb_process where pId=?", process.getId());
+        JSONArray step_list = JSON.parseArray(getPara("step_list"));
+        for (int i = 0; i < step_list.size(); i++) {
+            JSONObject object = step_list.getJSONObject(i);
+            Process step = new Process();
+            step.setPId(process.getId());
+            step.setName(object.getString("name"));
+            step.setSteps(i + 1);
+            step.setApproval(object.getString("approval"));
+            step.save();
+        }
+        renderSuccess();
+    }
+
+    /**
+     * 删除
+     */
+    @RequiresPermissions("process:delete")
+    public void delete() {
+        Db.update("delete from tb_process where id in(" + getPara("ids") + ")");
+        renderSuccess();
+    }
+}

+ 92 - 0
src/main/java/com/lsw/controller/front/ApplyController.java

@@ -0,0 +1,92 @@
+package com.lsw.controller.front;
+
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Record;
+import com.lsw.base.BaseController;
+import com.lsw.model.Apply;
+import com.lsw.model.Process;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class ApplyController extends BaseController {
+
+
+    public void process_list() {
+        List<Process> process_list = Process.dao.find("select * from tb_process where pId=0");
+        renderJson(process_list);
+
+    }
+
+    public void apply_save() {
+        Apply apply = getModel(Apply.class, "", true);
+        apply.setMDate(new Date());
+        apply.setSteps(1);
+        apply.save();
+        renderSuccess();
+    }
+
+    /**
+     * 申请单
+     */
+    public void apply_list() {
+        List<Apply> apply_list = Apply.dao.jsonList(getParaToInt("userId"), getPara("name"));
+        for (Apply apply : apply_list) {
+            Process process = Process.dao.findFirst("select * from tb_process where pId=? and steps=?", apply.getProcessId(), apply.getSteps());
+            if (process == null) {
+                apply.put("now", "结束");
+            } else {
+                apply.put("now", process.getName());
+            }
+        }
+        renderJson(apply_list);
+    }
+
+    /**
+     * 待办
+     */
+    public void backlog_list() {
+        List<Apply> apply_list = Apply.dao.jsonList();
+        List<Apply> backlog_list = new ArrayList<>();
+        String roleId = getPara("roleId");
+        for (Apply apply : apply_list) {
+            Process process = Process.dao.findFirst("select * from tb_process where pId=? and steps=?", apply.getProcessId(), apply.getSteps());
+            if (process == null) {
+                apply.put("now", "结束");
+            } else {
+                apply.put("now", process.getName());
+            }
+            List<Process> process_list = Process.dao.find("select * from tb_process where pId=?", apply.getProcessId());
+            for (Process p : process_list) {
+                if (p.getApproval().contains(roleId)) {
+                    backlog_list.add(apply);
+                }
+            }
+        }
+        renderJson(backlog_list);
+    }
+
+    public void audit() {
+        Apply apply = getModel(Apply.class, "", true);
+        List<Process> step_list = Process.dao.find("select * from tb_process where pId=?", apply.getProcessId());
+        if(apply.getSteps()>step_list.size()){
+            apply.setState(1);
+        }
+        apply.update();
+        renderSuccess();
+    }
+
+    public void apply_detail() {
+        String roleId = getPara("roleId");
+        List<Process> step_list = Process.dao.find("select * from tb_process where pId=?", getPara("processId"));
+        Record record=new Record();
+        for(Process p:step_list) {
+            if (p.getApproval().contains(roleId)) {
+                record.set("step",p.getSteps());
+            }
+        }
+        record.set("step_list",step_list);
+        renderJson(record);
+    }
+}

+ 53 - 0
src/main/java/com/lsw/controller/front/ShareController.java

@@ -0,0 +1,53 @@
+package com.lsw.controller.front;
+
+import com.jfinal.aop.Before;
+import com.jfinal.kit.PathKit;
+import com.lsw.base.BaseController;
+import com.lsw.commons.utils.TimeUtil;
+import com.lsw.model.File;
+
+public class ShareController extends BaseController {
+
+    public void index() {
+        File file = File.dao.findFirst("select * from sys_file where fileFlag=? and isShare=1", getPara("surl", "aa"));
+        if (file == null) {
+            render("error.html");
+            return;
+        }
+        setAttr("file", file);
+        setAttr("time", TimeUtil.friendly_time(file.getStr("shareTime")));
+        render("index.html");
+    }
+
+    /**
+     * 验证下载文件
+     */
+    @Before(ShareValidator.class)
+    public void validate() {
+        File file = File.dao.findFirst("select * from sys_file where id=? and isShare=1", getPara("id"));
+        if (file.getIsOpen() == 1 && !getPara("pass").equals(file.getAllowPass())) {
+            renderError("提取码错误");
+            return;
+        }
+        renderSuccess();
+    }
+
+    /**
+     * 下载文件
+     */
+    //@Before(ShareValidator.class)
+    public void download() {
+        File file = File.dao.findFirst("select * from sys_file where id=? and isShare=1", getPara("id"));
+        if (file == null) {
+            renderError(404);
+            return;
+        }
+        if (file.getIsOpen() == 1 && !getPara("pass", "0").equals(file.getAllowPass())) {
+            renderError("提取码错误");
+            return;
+        }
+        file.setDownloads(file.getDownloads() + 1);
+        file.update();
+        renderFile(new java.io.File(PathKit.getWebRootPath() + file.getFilePath()));
+    }
+}

+ 13 - 0
src/main/java/com/lsw/controller/front/ShareValidator.java

@@ -0,0 +1,13 @@
+package com.lsw.controller.front;
+
+import com.jfinal.core.Controller;
+import com.lsw.base.BaseValidator;
+
+public class ShareValidator extends BaseValidator {
+
+    @Override
+    protected void validate(Controller c) {
+        validateRequiredString("code", "msg", "验证码不能为空");
+        validateCaptcha("code", "msg", "验证码不正确");
+    }
+}

+ 23 - 0
src/main/java/com/lsw/controller/front/user/AppUserController.java

@@ -0,0 +1,23 @@
+package com.lsw.controller.front.user;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Clear;
+import com.jfinal.kit.Ret;
+import com.lsw.base.BaseController;
+import com.lsw.interceptor.TokenInterceptor;
+
+@Before(TokenInterceptor.class)
+public class AppUserController extends BaseController {
+    static final AppUserService appUserService = new AppUserService();
+
+
+
+    @Clear
+    @Before(AppUserValidator.class)
+    public void login() {
+        Ret ret = appUserService.login(getPara("account").trim(), getPara("password").trim());
+        renderJson(ret);
+    }
+
+
+}

+ 71 - 0
src/main/java/com/lsw/controller/front/user/AppUserService.java

@@ -0,0 +1,71 @@
+package com.lsw.controller.front.user;
+
+import com.jfinal.kit.HashKit;
+import com.jfinal.kit.Ret;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.lsw.commons.utils.Constant;
+import com.lsw.model.Token;
+import com.lsw.model.User;
+import org.apache.shiro.crypto.hash.SimpleHash;
+import org.apache.shiro.util.SimpleByteSource;
+
+/**
+ * Created by Administrator on 2017/5/23.
+ */
+public class AppUserService {
+    private final User dao = new User().dao();
+
+    public Ret login(String account, String password) {
+        Ret ret = Ret.create();
+        StringBuilder sb=new StringBuilder();
+        sb.append("SELECT u.*,ur.roleId,r.roleName,d.departmentName");
+        sb.append(" FROM sys_user u");
+        sb.append(" LEFT JOIN sys_user_role ur ON ur.userId=u.id");
+        sb.append(" LEFT JOIN sys_role r ON r.id=ur.roleId");
+        sb.append(" LEFT JOIN sys_department d ON d.id=u.depId");
+        sb.append(" WHERE u.account=?");
+        User user = dao.findFirst(sb.toString(), account);
+        if (user == null) {
+            ret.set("result", false).set("msg", "账户或密码错误!");
+            return ret;
+        }
+        String pass=new SimpleHash("MD5", new SimpleByteSource(password), new SimpleByteSource(user.getSalt()), 2).toHex();
+        if(!pass.equals(user.getPassword())){
+            ret.set("result", false).set("msg", "账户或密码错误!");
+            return ret;
+        }
+        if(user.getState()==1){
+            ret.set("result", false).set("msg", "该账户被限制登录");
+            return ret;
+        }
+        //保存token信息
+        Token token = new Token();
+        String secret = HashKit.generateSaltForSha256();
+        token.setSecret(secret);
+        token.put("state", 0);
+        token.setAccount(user.getAccount());
+        token.save();
+        user.put("token", secret);
+        CacheKit.put(Constant.token, account, token);
+        ret.set("result", true);
+        ret.set("user", user);
+        return ret;
+    }
+
+    /**
+     * 用户验证token知否有效
+     *
+     * @param secret
+     * @param account
+     * @return
+     */
+    public Token loginBySecret(String secret, String account) {
+        Token token = CacheKit.get(Constant.token, account);
+        if (token == null) {
+            token = Token.dao.findFirst("SELECT u.state FROM tb_token t LEFT JOIN sys_user u ON u.account = t.account WHERE t.secret=? AND t.account=? ORDER BY t.id DESC", secret, account);
+            CacheKit.put(Constant.token, account, token);
+        }
+        return token;
+    }
+
+}

+ 19 - 0
src/main/java/com/lsw/controller/front/user/AppUserValidator.java

@@ -0,0 +1,19 @@
+package com.lsw.controller.front.user;
+
+import com.jfinal.core.Controller;
+import com.lsw.base.BaseValidator;
+
+public class AppUserValidator extends BaseValidator {
+    @Override
+    protected void validate(Controller c) {
+        String url = getActionKey();
+        if (url.equals("/app/user/login")) {
+            validateRequiredString("account", "msg", "账号不能为空");
+        }
+        if (url.equals("/app/user/edit")) {
+            if (c.getPara("field").equals("phone")) {
+                validatePhone("value", "msg", "手机号格式不正确");
+            }
+        }
+    }
+}

+ 25 - 0
src/main/java/com/lsw/handler/ForbidHandler.java

@@ -0,0 +1,25 @@
+package com.lsw.handler;
+
+import com.jfinal.handler.Handler;
+import com.jfinal.kit.HandlerKit;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * @author 李书文
+ * @description
+ * @time 2017215
+ */
+public class ForbidHandler extends Handler {
+
+    @Override
+    public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
+        if (target.contains("/upload/file/")) {
+            HandlerKit.renderError404(request,response,isHandled);
+        }else{
+            next.handle(target, request, response, isHandled);
+        }
+    }
+    }

+ 25 - 0
src/main/java/com/lsw/handler/StaticHandler.java

@@ -0,0 +1,25 @@
+package com.lsw.handler;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.jfinal.handler.Handler;
+
+/**
+ * 静态化
+ * @author 李书文
+ * @description 
+ * @time 2017215
+ */
+public class StaticHandler extends Handler  {
+
+	@Override
+	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
+		 int index = target.lastIndexOf(".html");
+		    if (index != -1) {
+		      target = target.substring(0, index);
+		    }
+		    next.handle(target, request, response, isHandled);
+		  }
+
+}

+ 27 - 0
src/main/java/com/lsw/handler/XssHandler.java

@@ -0,0 +1,27 @@
+package com.lsw.handler;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.jfinal.handler.Handler;
+import com.lsw.commons.utils.HttpServletRequestWrapper;
+/**
+ * 处理xss攻击
+ * @author 李书文
+ * @description 
+ * @time 2017215
+ */
+public class XssHandler extends Handler {
+
+	@Override
+	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
+		 // 对于非静态文件,和非指定排除的url实现过滤
+        //我这里过滤的是资源文件和网站后台
+        if (target.indexOf(".") == -1){
+            request = new HttpServletRequestWrapper(request);
+        }
+        next.handle(target, request, response, isHandled);
+
+	}
+
+}

+ 22 - 0
src/main/java/com/lsw/interceptor/AccessAllowInterceptor.java

@@ -0,0 +1,22 @@
+package com.lsw.interceptor;
+
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+
+/**
+ * 设置跨域支持
+ * @author 李书文
+ * @description 
+ * @time 2017215
+ */
+public class AccessAllowInterceptor implements Interceptor {
+
+	public void intercept(Invocation inv) {
+		// 增加跨域支持响应头
+		inv.getController().getResponse().addHeader("Access-Control-Allow-Origin", "*");
+		inv.getController().getResponse().addHeader("Access-Control-Allow-Headers","X-Requested-With,token");
+		inv.getController().getResponse().addHeader("Access-Control-Allow-Headers","X-Requested-With,account");
+		inv.invoke();
+	}
+
+}

+ 25 - 0
src/main/java/com/lsw/interceptor/GlobalExceptionInterceptor.java

@@ -0,0 +1,25 @@
+package com.lsw.interceptor;
+
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+
+/**
+ * 对系统异常时的统一处理
+ */
+public class GlobalExceptionInterceptor implements Interceptor {
+
+	public void intercept(Invocation inv) {
+		Controller controller = inv.getController();
+		try {
+			inv.invoke();
+		} catch (Throwable e) {
+			Record record = new Record();
+			record.set("result", false);
+			record.set("msg", e.getMessage());
+			controller.renderJson(record);
+		}
+
+	}
+}

+ 24 - 0
src/main/java/com/lsw/interceptor/LogInterceptor.java

@@ -0,0 +1,24 @@
+package com.lsw.interceptor;
+
+import com.jfinal.aop.Duang;
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+import com.lsw.controller.admin.system.log.operation.OlogService;
+import com.lsw.shiro.tag.ShiroTag;
+
+/**
+ * Created by lishuwen on 2017/5/31.
+ */
+public class LogInterceptor implements Interceptor {
+    public void intercept(Invocation inv) {
+        String action = inv.getActionKey();
+        if (action.contains("add")) {
+            Duang.duang(OlogService.class).addLog(ShiroTag.getUser().getId(), "添加", "方法:" + action + ",参数:" + inv.getController().getParaMap().toString());
+        } else if (action.contains("edit")) {
+            Duang.duang(OlogService.class).addLog(ShiroTag.getUser().getId(), "编辑", "方法:" + action + ",参数:" + inv.getController().getParaMap().toString());
+        } else if (action.contains("delete")) {
+            Duang.duang(OlogService.class).addLog(ShiroTag.getUser().getId(), "删除", "方法:" + action + ",参数:" + inv.getController().getParaMap().toString());
+        }
+        inv.invoke();
+    }
+}

+ 36 - 0
src/main/java/com/lsw/interceptor/RoleMenuInterceptor.java

@@ -0,0 +1,36 @@
+package com.lsw.interceptor;
+
+import java.util.List;
+
+import com.jfinal.aop.Duang;
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+import com.lsw.controller.admin.system.menu.MenuService;
+import com.lsw.model.Menu;
+import com.lsw.model.User;
+import com.lsw.shiro.tag.ShiroTag;
+
+/**
+ * 通过获取xx/list的url查询菜单进而通过菜单的pid查询该菜单下面的授权按钮
+ */
+public class RoleMenuInterceptor implements Interceptor {
+    public void intercept(Invocation inv) {
+        if (null!=ShiroTag.getSubject().getPrincipals()) {
+            User user=ShiroTag.getUser();
+            if(user==null){
+                inv.getController().renderError(401);
+            }
+            String url = inv.getActionKey();
+            if (url.contains("list")) {
+                MenuService menuService=Duang.duang(MenuService.class);
+                Menu menu =menuService.getMenuByUrl(url);
+                if (menu != null) {
+                    List<Menu> menuList =menuService.getRoleButtonList(user.getInt("roleId"), menu.getId());
+                    inv.getController().setAttr("menu_list", menuList);
+                }
+            }
+            inv.getController().setAttr("user", user);
+        }
+        inv.invoke();
+    }
+}

+ 26 - 0
src/main/java/com/lsw/interceptor/TokenInterceptor.java

@@ -0,0 +1,26 @@
+package com.lsw.interceptor;
+
+import com.jfinal.aop.Duang;
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.Ret;
+import com.lsw.controller.front.user.AppUserService;
+import com.lsw.model.Token;
+
+public class TokenInterceptor implements Interceptor {
+    public void intercept(Invocation inv) {
+        Controller c = inv.getController();
+        Token token = Duang.duang(AppUserService.class).loginBySecret(c.getHeader("token"),c.getHeader("account"));
+        if (token == null) {
+            c.renderJson(Ret.create().set("result", false).set("msg", "请先登录"));
+            return;
+        }
+        if(token.getInt("state")==1){
+            c.renderJson(Ret.create().set("result", false).set("msg", "你已被锁定,不能做其它操作"));
+            return;
+        }
+        inv.invoke();
+    }
+
+}

+ 63 - 0
src/main/java/com/lsw/model/Apply.java

@@ -0,0 +1,63 @@
+package com.lsw.model;
+
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.base.BaseApply;
+
+import java.util.List;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Apply extends BaseApply<Apply> {
+    public static final Apply dao = new Apply().dao();
+
+    public Page<Apply> jsonList(int page, int row, String name, String sidx, String sord) {
+        String select = "SELECT a.*,p.name AS processName,u.realName";
+        StringBuilder sb = new StringBuilder();
+        sb.append(" FROM tb_apply a");
+        sb.append(" LEFT JOIN tb_process p ON p.id=a.processId");
+        sb.append(" LEFT JOIN sys_user u ON u.id=a.userId");
+        sb.append(" WHERE 1=1");
+        if (StrKit.notBlank(name)) {
+            sb.append(" AND a.name like '%" + name + "%'");
+        }
+        sb.append(" ORDER BY a." + sidx + " " + sord);
+        return dao.paginate(page, row, select, sb.toString());
+    }
+
+    public List<Apply> jsonList(int userId,String name) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(" SELECT a.*,p.name AS processName,u.realName");
+        sb.append(" FROM tb_apply a");
+        sb.append(" LEFT JOIN tb_process p ON p.id=a.processId");
+        sb.append(" LEFT JOIN sys_user u ON u.id=a.userId");
+        sb.append(" WHERE 1=1");
+        if (StrKit.notBlank(name)) {
+            sb.append(" AND a.name like '%" + name + "%'");
+        }
+        sb.append(" AND u.id="+userId);
+        sb.append(" ORDER BY a.mDate desc");
+        return dao.find(sb.toString());
+    }
+    public List<Apply> jsonList() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(" SELECT a.*,p.name AS processName,u.realName");
+        sb.append(" FROM tb_apply a");
+        sb.append(" LEFT JOIN tb_process p ON p.id=a.processId");
+        sb.append(" LEFT JOIN sys_user u ON u.id=a.userId");
+        sb.append(" ORDER BY a.id DESC");
+        return dao.find(sb.toString());
+    }
+
+    public Apply selectById(int id) {
+        StringBuilder sb = new StringBuilder();
+        sb.append(" SELECT a.*,p.name AS processName,u.realName");
+        sb.append(" FROM tb_apply a");
+        sb.append(" LEFT JOIN tb_process p ON p.id=a.processId");
+        sb.append(" LEFT JOIN sys_user u ON u.id=a.userId");
+        sb.append(" WHERE a.id=?");
+        return dao.findFirst(sb.toString(), id);
+    }
+}

+ 29 - 0
src/main/java/com/lsw/model/Constant.java

@@ -0,0 +1,29 @@
+package com.lsw.model;
+
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.base.BaseConstant;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Constant extends BaseConstant<Constant> {
+    public static final Constant dao = new Constant().dao();
+
+    public Page<Constant> jsonList(int page, int row, String name, String type, String sidx, String sord) {
+        String select = "SELECT id,name,type,CASE WHEN c.pId>0 THEN'常量' ELSE '类型' END AS pId";
+        StringBuilder sb = new StringBuilder();
+        sb.append(" FROM tb_constant c");
+        sb.append(" WHERE 1=1");
+        if (StrKit.notBlank(name)) {
+            sb.append(" AND c.name like '%" + name + "%'");
+        }
+        //选择类型
+        if (StrKit.notBlank(type)) {
+            sb.append(" AND c.pId='" + type + "'");
+        }
+        sb.append(" ORDER BY c." + sidx + " " + sord);
+        return dao.paginate(page, row, select, sb.toString());
+    }
+}

+ 11 - 0
src/main/java/com/lsw/model/Department.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseDepartment;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Department extends BaseDepartment<Department> {
+	public static final Department dao = new Department().dao();
+}

+ 48 - 0
src/main/java/com/lsw/model/File.java

@@ -0,0 +1,48 @@
+package com.lsw.model;
+
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.base.BaseFile;
+
+import java.util.List;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class File extends BaseFile<File> {
+    public static final File dao = new File().dao();
+
+
+    public List<File> list() {
+        return dao.find("SELECT f.*,u.realName,d.departmentName FROM sys_file f LEFT JOIN sys_user u ON u.id=f.userId LEFT JOIN sys_department d ON d.id=u.depId ORDER BY f.uploadTime DESC LIMIT 10");
+    }
+
+    public Page<File> jsonList(int page, int row, String fileName, String fileType,String department,int isDelete, int isShare, String min, String max, String sidx, String sord) {
+        String select = "SELECT f.*,u.realName,d.departmentName";
+        StringBuilder sb = new StringBuilder();
+        sb.append(" FROM sys_file f");
+        sb.append(" LEFT JOIN sys_user u ON u.id=f.userId");
+        sb.append(" LEFT JOIN sys_department d ON d.id=u.depId");
+        sb.append(" WHERE 1=1");
+        if (StrKit.notBlank(fileName)) {
+            sb.append(" AND f.fileName like '%" + fileName + "%'");
+        }
+        if (StrKit.notBlank(fileType)) {
+            sb.append(" AND f.fileType='" + fileType + "'");
+        }
+        if (StrKit.notBlank(min)) {
+            sb.append("  AND f.uploadTime BETWEEN '" + min + "' AND '" + max + "'");
+        }
+        if (isShare != 0) {
+            sb.append(" AND f.isShare=1");
+        }
+        //选择部门
+        if (StrKit.notBlank(department)) {
+            sb.append(" AND d.departmentName='" + department + "'");
+        }
+        sb.append(" AND f.isDelete=" + isDelete);
+        sb.append(" ORDER BY f." + sidx + " " + sord);
+        return dao.paginate(page, row, select, sb.toString());
+    }
+}

+ 11 - 0
src/main/java/com/lsw/model/Letter.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseLetter;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Letter extends BaseLetter<Letter> {
+	public static final Letter dao = new Letter().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/LetterUser.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseLetterUser;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class LetterUser extends BaseLetterUser<LetterUser> {
+	public static final LetterUser dao = new LetterUser().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/LoginLog.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseLoginLog;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class LoginLog extends BaseLoginLog<LoginLog> {
+	public static final LoginLog dao = new LoginLog().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/Menu.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseMenu;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Menu extends BaseMenu<Menu> {
+	public static final Menu dao = new Menu().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/MenuRole.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseMenuRole;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class MenuRole extends BaseMenuRole<MenuRole> {
+	public static final MenuRole dao = new MenuRole().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/OperationLog.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseOperationLog;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class OperationLog extends BaseOperationLog<OperationLog> {
+	public static final OperationLog dao = new OperationLog().dao();
+}

+ 26 - 0
src/main/java/com/lsw/model/Process.java

@@ -0,0 +1,26 @@
+package com.lsw.model;
+
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Page;
+import com.lsw.model.base.BaseProcess;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Process extends BaseProcess<Process> {
+	public static final Process dao = new Process().dao();
+
+	public Page<Process> jsonList(int page, int row, String name,String sidx, String sord) {
+		String select = "SELECT p.*";
+		StringBuilder sb = new StringBuilder();
+		sb.append(" FROM tb_process p");
+		sb.append(" WHERE 1=1");
+		if (StrKit.notBlank(name)) {
+			sb.append(" AND p.name like '%" + name + "%'");
+		}
+		sb.append(" AND p.pId=0");
+		sb.append(" ORDER BY p." + sidx + " " + sord);
+		return dao.paginate(page, row, select, sb.toString());
+	}
+}

+ 11 - 0
src/main/java/com/lsw/model/Role.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseRole;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Role extends BaseRole<Role> {
+	public static final Role dao = new Role().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/Token.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseToken;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class Token extends BaseToken<Token> {
+	public static final Token dao = new Token().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/User.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseUser;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class User extends BaseUser<User> {
+	public static final User dao = new User().dao();
+}

+ 11 - 0
src/main/java/com/lsw/model/UserRole.java

@@ -0,0 +1,11 @@
+package com.lsw.model;
+
+import com.lsw.model.base.BaseUserRole;
+
+/**
+ * Generated by JFinal.
+ */
+@SuppressWarnings("serial")
+public class UserRole extends BaseUserRole<UserRole> {
+	public static final UserRole dao = new UserRole().dao();
+}

+ 36 - 0
src/main/java/com/lsw/model/_MappingKit.java

@@ -0,0 +1,36 @@
+package com.lsw.model;
+
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ * <pre>
+ * Example:
+ * public void configPlugin(Plugins me) {
+ *     ActiveRecordPlugin arp = new ActiveRecordPlugin(...);
+ *     _MappingKit.mapping(arp);
+ *     me.add(arp);
+ * }
+ * </pre>
+ */
+public class _MappingKit {
+
+	public static void mapping(ActiveRecordPlugin arp) {
+		arp.addMapping("sys_department", "id", Department.class);
+		arp.addMapping("sys_file", "id", File.class);
+		arp.addMapping("sys_letter", "id", Letter.class);
+		arp.addMapping("sys_letter_user", "id", LetterUser.class);
+		arp.addMapping("sys_login_log", "id", LoginLog.class);
+		arp.addMapping("sys_menu", "id", Menu.class);
+		arp.addMapping("sys_menu_role", "id", MenuRole.class);
+		arp.addMapping("sys_operation_log", "id", OperationLog.class);
+		arp.addMapping("sys_role", "id", Role.class);
+		arp.addMapping("sys_user", "id", User.class);
+		arp.addMapping("sys_user_role", "id", UserRole.class);
+		arp.addMapping("tb_apply", "id", Apply.class);
+		arp.addMapping("tb_constant", "id", Constant.class);
+		arp.addMapping("tb_process", "id", Process.class);
+		arp.addMapping("tb_token", "id", Token.class);
+	}
+}
+

+ 84 - 0
src/main/java/com/lsw/model/base/BaseApply.java

@@ -0,0 +1,84 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseApply<M extends BaseApply<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setName(java.lang.String name) {
+		set("name", name);
+	}
+
+	public java.lang.String getName() {
+		return getStr("name");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setProcessId(java.lang.Integer processId) {
+		set("processId", processId);
+	}
+
+	public java.lang.Integer getProcessId() {
+		return getInt("processId");
+	}
+
+	public void setSteps(java.lang.Integer steps) {
+		set("steps", steps);
+	}
+
+	public java.lang.Integer getSteps() {
+		return getInt("steps");
+	}
+
+	public void setState(java.lang.Integer state) {
+		set("state", state);
+	}
+
+	public java.lang.Integer getState() {
+		return getInt("state");
+	}
+
+	public void setMContent(java.lang.String mContent) {
+		set("mContent", mContent);
+	}
+
+	public java.lang.String getMContent() {
+		return getStr("mContent");
+	}
+
+	public void setAccessory(java.lang.String accessory) {
+		set("accessory", accessory);
+	}
+
+	public java.lang.String getAccessory() {
+		return getStr("accessory");
+	}
+
+	public void setMDate(java.util.Date mDate) {
+		set("mDate", mDate);
+	}
+
+	public java.util.Date getMDate() {
+		return get("mDate");
+	}
+
+}

+ 44 - 0
src/main/java/com/lsw/model/base/BaseConstant.java

@@ -0,0 +1,44 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseConstant<M extends BaseConstant<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setName(java.lang.String name) {
+		set("name", name);
+	}
+
+	public java.lang.String getName() {
+		return getStr("name");
+	}
+
+	public void setPId(java.lang.Integer pId) {
+		set("pId", pId);
+	}
+
+	public java.lang.Integer getPId() {
+		return getInt("pId");
+	}
+
+	public void setType(java.lang.Integer type) {
+		set("type", type);
+	}
+
+	public java.lang.Integer getType() {
+		return getInt("type");
+	}
+
+}

+ 68 - 0
src/main/java/com/lsw/model/base/BaseDepartment.java

@@ -0,0 +1,68 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseDepartment<M extends BaseDepartment<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setDepartmentName(java.lang.String departmentName) {
+		set("departmentName", departmentName);
+	}
+
+	public java.lang.String getDepartmentName() {
+		return getStr("departmentName");
+	}
+
+	public void setNumber(java.lang.String number) {
+		set("number", number);
+	}
+
+	public java.lang.String getNumber() {
+		return getStr("number");
+	}
+
+	public void setPId(java.lang.Integer pId) {
+		set("pId", pId);
+	}
+
+	public java.lang.Integer getPId() {
+		return getInt("pId");
+	}
+
+	public void setOpen(java.lang.String open) {
+		set("open", open);
+	}
+
+	public java.lang.String getOpen() {
+		return getStr("open");
+	}
+
+	public void setMark(java.lang.String mark) {
+		set("mark", mark);
+	}
+
+	public java.lang.String getMark() {
+		return getStr("mark");
+	}
+
+	public void setViewSort(java.lang.Integer viewSort) {
+		set("viewSort", viewSort);
+	}
+
+	public java.lang.Integer getViewSort() {
+		return getInt("viewSort");
+	}
+
+}

+ 156 - 0
src/main/java/com/lsw/model/base/BaseFile.java

@@ -0,0 +1,156 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseFile<M extends BaseFile<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setFileName(java.lang.String fileName) {
+		set("fileName", fileName);
+	}
+
+	public java.lang.String getFileName() {
+		return getStr("fileName");
+	}
+
+	public void setFileFlag(java.lang.String fileFlag) {
+		set("fileFlag", fileFlag);
+	}
+
+	public java.lang.String getFileFlag() {
+		return getStr("fileFlag");
+	}
+
+	public void setFileType(java.lang.String fileType) {
+		set("fileType", fileType);
+	}
+
+	public java.lang.String getFileType() {
+		return getStr("fileType");
+	}
+
+	public void setFileSize(java.lang.String fileSize) {
+		set("fileSize", fileSize);
+	}
+
+	public java.lang.String getFileSize() {
+		return getStr("fileSize");
+	}
+
+	public void setRealPath(java.lang.String realPath) {
+		set("realPath", realPath);
+	}
+
+	public java.lang.String getRealPath() {
+		return getStr("realPath");
+	}
+
+	public void setDCode(java.lang.String dCode) {
+		set("dCode", dCode);
+	}
+
+	public java.lang.String getDCode() {
+		return getStr("dCode");
+	}
+
+	public void setFilePath(java.lang.String filePath) {
+		set("filePath", filePath);
+	}
+
+	public java.lang.String getFilePath() {
+		return getStr("filePath");
+	}
+
+	public void setIsShare(java.lang.Integer isShare) {
+		set("isShare", isShare);
+	}
+
+	public java.lang.Integer getIsShare() {
+		return getInt("isShare");
+	}
+
+	public void setShareUrl(java.lang.String shareUrl) {
+		set("shareUrl", shareUrl);
+	}
+
+	public java.lang.String getShareUrl() {
+		return getStr("shareUrl");
+	}
+
+	public void setShareTime(java.util.Date shareTime) {
+		set("shareTime", shareTime);
+	}
+
+	public java.util.Date getShareTime() {
+		return get("shareTime");
+	}
+
+	public void setIsOpen(java.lang.Integer isOpen) {
+		set("isOpen", isOpen);
+	}
+
+	public java.lang.Integer getIsOpen() {
+		return getInt("isOpen");
+	}
+
+	public void setAllowPass(java.lang.String allowPass) {
+		set("allowPass", allowPass);
+	}
+
+	public java.lang.String getAllowPass() {
+		return getStr("allowPass");
+	}
+
+	public void setDownloads(java.lang.Integer downloads) {
+		set("downloads", downloads);
+	}
+
+	public java.lang.Integer getDownloads() {
+		return getInt("downloads");
+	}
+
+	public void setValidity(java.lang.Integer validity) {
+		set("validity", validity);
+	}
+
+	public java.lang.Integer getValidity() {
+		return getInt("validity");
+	}
+
+	public void setIsDelete(java.lang.Integer isDelete) {
+		set("isDelete", isDelete);
+	}
+
+	public java.lang.Integer getIsDelete() {
+		return getInt("isDelete");
+	}
+
+	public void setUploadTime(java.util.Date uploadTime) {
+		set("uploadTime", uploadTime);
+	}
+
+	public java.util.Date getUploadTime() {
+		return get("uploadTime");
+	}
+
+}

+ 92 - 0
src/main/java/com/lsw/model/base/BaseLetter.java

@@ -0,0 +1,92 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseLetter<M extends BaseLetter<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setTitle(java.lang.String title) {
+		set("title", title);
+	}
+
+	public java.lang.String getTitle() {
+		return getStr("title");
+	}
+
+	public void setContent(java.lang.String content) {
+		set("content", content);
+	}
+
+	public java.lang.String getContent() {
+		return getStr("content");
+	}
+
+	public void setType(java.lang.String type) {
+		set("type", type);
+	}
+
+	public java.lang.String getType() {
+		return getStr("type");
+	}
+
+	public void setPriority(java.lang.String priority) {
+		set("priority", priority);
+	}
+
+	public java.lang.String getPriority() {
+		return getStr("priority");
+	}
+
+	public void setSendObject(java.lang.String sendObject) {
+		set("sendObject", sendObject);
+	}
+
+	public java.lang.String getSendObject() {
+		return getStr("sendObject");
+	}
+
+	public void setSignature(java.lang.String signature) {
+		set("signature", signature);
+	}
+
+	public java.lang.String getSignature() {
+		return getStr("signature");
+	}
+
+	public void setState(java.lang.Integer state) {
+		set("state", state);
+	}
+
+	public java.lang.Integer getState() {
+		return getInt("state");
+	}
+
+	public void setSendTime(java.util.Date sendTime) {
+		set("sendTime", sendTime);
+	}
+
+	public java.util.Date getSendTime() {
+		return get("sendTime");
+	}
+
+}

+ 52 - 0
src/main/java/com/lsw/model/base/BaseLetterUser.java

@@ -0,0 +1,52 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseLetterUser<M extends BaseLetterUser<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setLetterId(java.lang.Integer letterId) {
+		set("letterId", letterId);
+	}
+
+	public java.lang.Integer getLetterId() {
+		return getInt("letterId");
+	}
+
+	public void setState(java.lang.Integer state) {
+		set("state", state);
+	}
+
+	public java.lang.Integer getState() {
+		return getInt("state");
+	}
+
+	public void setReceivedTime(java.util.Date receivedTime) {
+		set("receivedTime", receivedTime);
+	}
+
+	public java.util.Date getReceivedTime() {
+		return get("receivedTime");
+	}
+
+}

+ 68 - 0
src/main/java/com/lsw/model/base/BaseLoginLog.java

@@ -0,0 +1,68 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseLoginLog<M extends BaseLoginLog<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setAccount(java.lang.String account) {
+		set("account", account);
+	}
+
+	public java.lang.String getAccount() {
+		return getStr("account");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setOperation(java.lang.String operation) {
+		set("operation", operation);
+	}
+
+	public java.lang.String getOperation() {
+		return getStr("operation");
+	}
+
+	public void setCreateDate(java.util.Date createDate) {
+		set("createDate", createDate);
+	}
+
+	public java.util.Date getCreateDate() {
+		return get("createDate");
+	}
+
+	public void setRemark(java.lang.String remark) {
+		set("remark", remark);
+	}
+
+	public java.lang.String getRemark() {
+		return getStr("remark");
+	}
+
+	public void setIp(java.lang.String ip) {
+		set("ip", ip);
+	}
+
+	public java.lang.String getIp() {
+		return getStr("ip");
+	}
+
+}

+ 92 - 0
src/main/java/com/lsw/model/base/BaseMenu.java

@@ -0,0 +1,92 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseMenu<M extends BaseMenu<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setMenuName(java.lang.String menuName) {
+		set("menuName", menuName);
+	}
+
+	public java.lang.String getMenuName() {
+		return getStr("menuName");
+	}
+
+	public void setIcon(java.lang.String icon) {
+		set("icon", icon);
+	}
+
+	public java.lang.String getIcon() {
+		return getStr("icon");
+	}
+
+	public void setUrl(java.lang.String url) {
+		set("url", url);
+	}
+
+	public java.lang.String getUrl() {
+		return getStr("url");
+	}
+
+	public void setPermission(java.lang.String permission) {
+		set("permission", permission);
+	}
+
+	public java.lang.String getPermission() {
+		return getStr("permission");
+	}
+
+	public void setPId(java.lang.Integer pId) {
+		set("pId", pId);
+	}
+
+	public java.lang.Integer getPId() {
+		return getInt("pId");
+	}
+
+	public void setOpen(java.lang.String open) {
+		set("open", open);
+	}
+
+	public java.lang.String getOpen() {
+		return getStr("open");
+	}
+
+	public void setMark(java.lang.String mark) {
+		set("mark", mark);
+	}
+
+	public java.lang.String getMark() {
+		return getStr("mark");
+	}
+
+	public void setViewSort(java.lang.Integer viewSort) {
+		set("viewSort", viewSort);
+	}
+
+	public java.lang.Integer getViewSort() {
+		return getInt("viewSort");
+	}
+
+	public void setResourcesType(java.lang.Integer resourcesType) {
+		set("resourcesType", resourcesType);
+	}
+
+	public java.lang.Integer getResourcesType() {
+		return getInt("resourcesType");
+	}
+
+}

+ 36 - 0
src/main/java/com/lsw/model/base/BaseMenuRole.java

@@ -0,0 +1,36 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseMenuRole<M extends BaseMenuRole<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setMenuId(java.lang.Integer menuId) {
+		set("menuId", menuId);
+	}
+
+	public java.lang.Integer getMenuId() {
+		return getInt("menuId");
+	}
+
+	public void setRoleId(java.lang.Integer roleId) {
+		set("roleId", roleId);
+	}
+
+	public java.lang.Integer getRoleId() {
+		return getInt("roleId");
+	}
+
+}

+ 52 - 0
src/main/java/com/lsw/model/base/BaseOperationLog.java

@@ -0,0 +1,52 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseOperationLog<M extends BaseOperationLog<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setOperation(java.lang.String operation) {
+		set("operation", operation);
+	}
+
+	public java.lang.String getOperation() {
+		return getStr("operation");
+	}
+
+	public void setCreateDate(java.util.Date createDate) {
+		set("createDate", createDate);
+	}
+
+	public java.util.Date getCreateDate() {
+		return get("createDate");
+	}
+
+	public void setRemark(java.lang.String remark) {
+		set("remark", remark);
+	}
+
+	public java.lang.String getRemark() {
+		return getStr("remark");
+	}
+
+}

+ 76 - 0
src/main/java/com/lsw/model/base/BaseProcess.java

@@ -0,0 +1,76 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseProcess<M extends BaseProcess<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setName(java.lang.String name) {
+		set("name", name);
+	}
+
+	public java.lang.String getName() {
+		return getStr("name");
+	}
+
+	public void setState(java.lang.Integer state) {
+		set("state", state);
+	}
+
+	public java.lang.Integer getState() {
+		return getInt("state");
+	}
+
+	public void setSteps(java.lang.Integer steps) {
+		set("steps", steps);
+	}
+
+	public java.lang.Integer getSteps() {
+		return getInt("steps");
+	}
+
+	public void setPId(java.lang.Integer pId) {
+		set("pId", pId);
+	}
+
+	public java.lang.Integer getPId() {
+		return getInt("pId");
+	}
+
+	public void setStartTime(java.util.Date startTime) {
+		set("startTime", startTime);
+	}
+
+	public java.util.Date getStartTime() {
+		return get("startTime");
+	}
+
+	public void setEndTime(java.util.Date endTime) {
+		set("endTime", endTime);
+	}
+
+	public java.util.Date getEndTime() {
+		return get("endTime");
+	}
+
+	public void setApproval(java.lang.String approval) {
+		set("approval", approval);
+	}
+
+	public java.lang.String getApproval() {
+		return getStr("approval");
+	}
+
+}

+ 52 - 0
src/main/java/com/lsw/model/base/BaseRole.java

@@ -0,0 +1,52 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseRole<M extends BaseRole<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setRoleName(java.lang.String roleName) {
+		set("roleName", roleName);
+	}
+
+	public java.lang.String getRoleName() {
+		return getStr("roleName");
+	}
+
+	public void setEnable(java.lang.Integer enable) {
+		set("enable", enable);
+	}
+
+	public java.lang.Integer getEnable() {
+		return getInt("enable");
+	}
+
+	public void setNote(java.lang.String note) {
+		set("note", note);
+	}
+
+	public java.lang.String getNote() {
+		return getStr("note");
+	}
+
+	public void setPushTime(java.util.Date pushTime) {
+		set("pushTime", pushTime);
+	}
+
+	public java.util.Date getPushTime() {
+		return get("pushTime");
+	}
+
+}

+ 36 - 0
src/main/java/com/lsw/model/base/BaseToken.java

@@ -0,0 +1,36 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseToken<M extends BaseToken<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setSecret(java.lang.String secret) {
+		set("secret", secret);
+	}
+
+	public java.lang.String getSecret() {
+		return getStr("secret");
+	}
+
+	public void setAccount(java.lang.String account) {
+		set("account", account);
+	}
+
+	public java.lang.String getAccount() {
+		return getStr("account");
+	}
+
+}

+ 100 - 0
src/main/java/com/lsw/model/base/BaseUser.java

@@ -0,0 +1,100 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseUser<M extends BaseUser<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setAccount(java.lang.String account) {
+		set("account", account);
+	}
+
+	public java.lang.String getAccount() {
+		return getStr("account");
+	}
+
+	public void setPassword(java.lang.String password) {
+		set("password", password);
+	}
+
+	public java.lang.String getPassword() {
+		return getStr("password");
+	}
+
+	public void setSalt(java.lang.String salt) {
+		set("salt", salt);
+	}
+
+	public java.lang.String getSalt() {
+		return getStr("salt");
+	}
+
+	public void setRegion(java.lang.String region) {
+		set("region", region);
+	}
+
+	public java.lang.String getRegion() {
+		return getStr("region");
+	}
+
+	public void setRealName(java.lang.String realName) {
+		set("realName", realName);
+	}
+
+	public java.lang.String getRealName() {
+		return getStr("realName");
+	}
+
+	public void setEmail(java.lang.String email) {
+		set("email", email);
+	}
+
+	public java.lang.String getEmail() {
+		return getStr("email");
+	}
+
+	public void setPhone(java.lang.String phone) {
+		set("phone", phone);
+	}
+
+	public java.lang.String getPhone() {
+		return getStr("phone");
+	}
+
+	public void setDepId(java.lang.Integer depId) {
+		set("depId", depId);
+	}
+
+	public java.lang.Integer getDepId() {
+		return getInt("depId");
+	}
+
+	public void setState(java.lang.Integer state) {
+		set("state", state);
+	}
+
+	public java.lang.Integer getState() {
+		return getInt("state");
+	}
+
+	public void setReleaseTime(java.util.Date releaseTime) {
+		set("releaseTime", releaseTime);
+	}
+
+	public java.util.Date getReleaseTime() {
+		return get("releaseTime");
+	}
+
+}

+ 36 - 0
src/main/java/com/lsw/model/base/BaseUserRole.java

@@ -0,0 +1,36 @@
+package com.lsw.model.base;
+
+import com.jfinal.plugin.activerecord.Model;
+import com.jfinal.plugin.activerecord.IBean;
+
+/**
+ * Generated by JFinal, do not modify this file.
+ */
+@SuppressWarnings("serial")
+public abstract class BaseUserRole<M extends BaseUserRole<M>> extends Model<M> implements IBean {
+
+	public void setId(java.lang.Integer id) {
+		set("id", id);
+	}
+
+	public java.lang.Integer getId() {
+		return getInt("id");
+	}
+
+	public void setUserId(java.lang.Integer userId) {
+		set("userId", userId);
+	}
+
+	public java.lang.Integer getUserId() {
+		return getInt("userId");
+	}
+
+	public void setRoleId(java.lang.Integer roleId) {
+		set("roleId", roleId);
+	}
+
+	public java.lang.Integer getRoleId() {
+		return getInt("roleId");
+	}
+
+}

+ 45 - 0
src/main/java/com/lsw/route/AdminRoute.java

@@ -0,0 +1,45 @@
+package com.lsw.route;
+
+import com.jfinal.config.Routes;
+import com.lsw.controller.admin.system.department.DepartmentController;
+import com.lsw.controller.admin.system.file.FileController;
+import com.lsw.controller.admin.system.index.IndexController;
+import com.lsw.controller.admin.system.letter.LetterController;
+import com.lsw.controller.admin.system.log.login.LlogController;
+import com.lsw.controller.admin.system.log.operation.OlogController;
+import com.lsw.controller.admin.system.menu.MenuController;
+import com.lsw.controller.admin.system.role.RoleController;
+import com.lsw.controller.admin.system.upload.UploadController;
+import com.lsw.controller.admin.system.user.UserController;
+import com.lsw.controller.admin.work.apply.ApplyController;
+import com.lsw.controller.admin.work.constant.ConstantController;
+import com.lsw.controller.admin.work.process.ProcessController;
+import com.lsw.interceptor.LogInterceptor;
+import com.lsw.interceptor.RoleMenuInterceptor;
+
+public class AdminRoute extends Routes {
+
+    @Override
+    public void config() {
+        setBaseViewPath("/WEB-INF/view/admin");
+        addInterceptor(new RoleMenuInterceptor());
+        addInterceptor(new LogInterceptor());
+        /***************************************系统相关*****************************************/
+        add("/admin", IndexController.class, "/system/index/"); // 后台首页
+        add("/admin/user", UserController.class, "/system/user/"); // 用户管理
+        add("/admin/role", RoleController.class, "/system/role/"); // 角色管理
+        add("/admin/department", DepartmentController.class, "/system/department/"); // 部门管理
+        add("/admin/letter", LetterController.class, "/system/letter/"); // 站内信
+        add("/admin/menu", MenuController.class, "/system/menu/"); // 菜单管理
+        add("/admin/log/login", LlogController.class, "/system/log/login/"); // 登录日志管理
+        add("/admin/log/operation", OlogController.class, "/system/log/operation/"); // 操作日志管理
+        add("/admin/upload", UploadController.class); // 上传管理
+        add("/admin/file", FileController.class, "/system/file/"); // 文件管理
+
+        /***************************************业务相关*****************************************/
+        add("/admin/work/constant", ConstantController.class, "/work/constant"); // 平台常量
+        add("/admin/work/process", ProcessController.class, "/work/process"); // 流程
+        add("/admin/work/apply", ApplyController.class, "/work/apply"); // 申请单管理
+    }
+
+}

+ 18 - 0
src/main/java/com/lsw/route/FrontRoute.java

@@ -0,0 +1,18 @@
+package com.lsw.route;
+
+import com.jfinal.config.Routes;
+import com.lsw.controller.front.ApplyController;
+import com.lsw.controller.front.ShareController;
+import com.lsw.controller.front.user.AppUserController;
+
+public class FrontRoute extends Routes {
+    @Override
+    public void config() {
+        setBaseViewPath("/WEB-INF/view/front");
+        add("/share", ShareController.class, "/share/"); // 分享页
+        add("/app/apply", ApplyController.class); // 分享页
+        add("/app/user", AppUserController.class); // appuser
+
+    }
+
+}

+ 122 - 0
src/main/java/com/lsw/shiro/ShiroDbRealm.java

@@ -0,0 +1,122 @@
+package com.lsw.shiro;
+
+import com.jfinal.aop.Duang;
+import com.lsw.controller.admin.system.menu.MenuService;
+import com.lsw.controller.admin.system.role.RoleService;
+import com.lsw.controller.admin.system.user.UserService;
+import com.lsw.model.Menu;
+import com.lsw.model.Role;
+import com.lsw.model.User;
+import com.lsw.shiro.ext.ByteSource;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authc.*;
+import org.apache.shiro.authz.AuthorizationInfo;
+import org.apache.shiro.authz.SimpleAuthorizationInfo;
+import org.apache.shiro.realm.AuthorizingRealm;
+import org.apache.shiro.session.Session;
+import org.apache.shiro.session.mgt.DefaultSessionManager;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.shiro.subject.SimplePrincipalCollection;
+import org.apache.shiro.subject.support.DefaultSubjectContext;
+import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ShiroDbRealm extends AuthorizingRealm {
+    static final RoleService roleService = Duang.duang(RoleService.class);
+    static final MenuService menuService = Duang.duang(MenuService.class);
+    static final UserService userService = Duang.duang(UserService.class);
+
+    //授权
+    @Override
+    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
+        // 根据用户配置用户与权限
+        String account = (String) getAvailablePrincipal(principals);
+        SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
+        Role role = roleService.getRoleByAccount(account);
+        if (role == null) {
+            return info;
+        }
+        System.out.println("角色:" + role.getRoleName());
+        info.addRole(role.getRoleName());
+        List<Menu> menuRoles = menuService.getAuthorizationList(role.getId());
+        List<String> lists = new ArrayList<String>();
+        for (Menu menu : menuRoles) {
+            if (menu.getPermission() != null) {
+                System.out.println("权限:" + menu.getPermission());
+                lists.add(menu.getPermission());
+            }
+        }
+        info.addStringPermissions(lists);
+        return info;
+    }
+
+    //身份认证
+    @Override
+    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
+        UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
+        User user = userService.login(token.getUsername());
+        if (user == null) {
+            throw new UnknownAccountException();
+        }
+        if (user.getState() == 1) {
+            throw new LockedAccountException();
+        }
+        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(token.getUsername(), user.getPassword(), new ByteSource(user.getSalt().getBytes()), getName());
+        return info;
+    }
+
+    //更新自己的授权缓存
+    public void clearCached() {
+        PrincipalCollection principal = SecurityUtils.getSubject().getPrincipals();
+        System.out.println("清除缓存:" + principal);
+        super.clearCache(principal);
+    }
+
+    /**
+     * 更新全部授权缓存
+     */
+    public void clearAllAuthorizationCache() {
+        super.getAuthorizationCache().clear();
+    }
+
+    /**
+     * 更新指定用户的授权缓存
+     */
+    public void clearCacheAuthor(Object principal) {
+        SimplePrincipalCollection info = new SimplePrincipalCollection(principal, getName());
+        super.clearCachedAuthorizationInfo(info);
+    }
+
+    /**
+     * 更新指定用户的认证缓存
+     */
+    public void clearCacheAuthen(Object principal) {
+        SimplePrincipalCollection info = new SimplePrincipalCollection(principal, getName());
+        System.out.println("清除认证:" + principal);
+        super.clearCachedAuthenticationInfo(info);
+    }
+
+    public PrincipalCollection getPrincipal(String Account) {
+        return new SimplePrincipalCollection(Account, getName());
+    }
+
+    /**
+     * 剔除用户下线
+     *
+     * @param account
+     */
+    public void offline(String account) {
+        DefaultWebSecurityManager securityManager = (DefaultWebSecurityManager) SecurityUtils.getSecurityManager();
+        DefaultSessionManager sessionManager = (DefaultSessionManager) securityManager.getSessionManager();
+        for (Session session : sessionManager.getSessionDAO().getActiveSessions()) {
+            System.out.println("session:" + session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY));
+            if (account.equals(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY).toString())) {
+                session.setTimeout(0L);
+                System.out.println("下线");
+                break;
+            }
+        }
+    }
+}

+ 34 - 0
src/main/java/com/lsw/shiro/ext/AbstractAuthzHandler.java

@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2011-2013, dafei 李飞 (myaniu AT gmail DOT com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.lsw.shiro.ext;
+
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.subject.Subject;
+
+/**
+ * 访问控制抽象基类
+ * @author dafei
+ */
+abstract class AbstractAuthzHandler implements AuthzHandler {
+
+	/**
+	 * 获得Shiro的Subject对象。
+	 * @return
+	 */
+	 protected Subject getSubject() {
+	     return SecurityUtils.getSubject();
+	 }
+}

Деякі файли не було показано, через те що забагато файлів було змінено