wzh před 1 rokem
revize
890f41d063
100 změnil soubory, kde provedl 9752 přidání a 0 odebrání
  1. 5 0
      .gitignore
  2. 177 0
      pom.xml
  3. 13 0
      src/main/java/com/qlm/annotation/RequestUrl.java
  4. 14 0
      src/main/java/com/qlm/common/Define.java
  5. 128 0
      src/main/java/com/qlm/controller/AuthController.java
  6. 8 0
      src/main/java/com/qlm/controller/FeedBackController.java
  7. 44 0
      src/main/java/com/qlm/controller/HBRateController.java
  8. 87 0
      src/main/java/com/qlm/controller/IndexController.java
  9. 32 0
      src/main/java/com/qlm/controller/OperatingController.java
  10. 35 0
      src/main/java/com/qlm/controller/UploadController.java
  11. 304 0
      src/main/java/com/qlm/controller/common/CommonController.java
  12. 138 0
      src/main/java/com/qlm/controller/common/CommonUserController.java
  13. 27 0
      src/main/java/com/qlm/controller/core/AreaController.java
  14. 25 0
      src/main/java/com/qlm/controller/core/ConfigController.java
  15. 329 0
      src/main/java/com/qlm/controller/core/ProduceController.java
  16. 71 0
      src/main/java/com/qlm/controller/core/QrcodeAddController.java
  17. 94 0
      src/main/java/com/qlm/controller/core/RecordController.java
  18. 173 0
      src/main/java/com/qlm/controller/core/SearchController.java
  19. 20 0
      src/main/java/com/qlm/controller/core/ShiwuController.java
  20. 157 0
      src/main/java/com/qlm/controller/core/StatisticController.java
  21. 178 0
      src/main/java/com/qlm/controller/core/TjSearchController.java
  22. 232 0
      src/main/java/com/qlm/controller/core/TypeController.java
  23. 39 0
      src/main/java/com/qlm/controller/core/UnPayInfoController.java
  24. 181 0
      src/main/java/com/qlm/controller/editor/ConsumerController.java
  25. 127 0
      src/main/java/com/qlm/controller/editor/service/EditorService.java
  26. 263 0
      src/main/java/com/qlm/controller/hx/HexiaoController.java
  27. 92 0
      src/main/java/com/qlm/controller/hx/JxsController.java
  28. 43 0
      src/main/java/com/qlm/controller/jinzai/ProductController.java
  29. 21 0
      src/main/java/com/qlm/controller/jinzai/ProductTypeController.java
  30. 354 0
      src/main/java/com/qlm/controller/pj/AreaHbConfigController.java
  31. 103 0
      src/main/java/com/qlm/controller/pj/FirstZhongController.java
  32. 93 0
      src/main/java/com/qlm/controller/pj/RetailPjController.java
  33. 93 0
      src/main/java/com/qlm/controller/pj/YwyPjController.java
  34. 129 0
      src/main/java/com/qlm/controller/shanghu/ShanghuController.java
  35. 73 0
      src/main/java/com/qlm/controller/shanghu/service/BillServcie.java
  36. 98 0
      src/main/java/com/qlm/controller/system/ResController.java
  37. 159 0
      src/main/java/com/qlm/controller/system/RoleController.java
  38. 255 0
      src/main/java/com/qlm/controller/system/UserController.java
  39. 10 0
      src/main/java/com/qlm/entity/Admin.java
  40. 13 0
      src/main/java/com/qlm/entity/AreaHbConfig.java
  41. 14 0
      src/main/java/com/qlm/entity/AreaHbConfigRate.java
  42. 10 0
      src/main/java/com/qlm/entity/CreateQrcodeRecord.java
  43. 30 0
      src/main/java/com/qlm/entity/DayHbEntity.java
  44. 10 0
      src/main/java/com/qlm/entity/HBRate.java
  45. 26 0
      src/main/java/com/qlm/entity/HbEntity.java
  46. 12 0
      src/main/java/com/qlm/entity/Log.java
  47. 8 0
      src/main/java/com/qlm/entity/Master.java
  48. 13 0
      src/main/java/com/qlm/entity/Record.java
  49. 16 0
      src/main/java/com/qlm/entity/Res.java
  50. 10 0
      src/main/java/com/qlm/entity/ScanDetail.java
  51. 35 0
      src/main/java/com/qlm/entity/ScanHbEntity.java
  52. 10 0
      src/main/java/com/qlm/entity/ScanRecord.java
  53. 10 0
      src/main/java/com/qlm/entity/User.java
  54. 33 0
      src/main/java/com/qlm/interceptor/AdminOperate2Interceptor.java
  55. 77 0
      src/main/java/com/qlm/interceptor/AdminOperateInterceptor.java
  56. 42 0
      src/main/java/com/qlm/interceptor/AuthInterceptor.java
  57. 144 0
      src/main/java/com/qlm/jfinal/JfinalConfig.java
  58. 621 0
      src/main/java/com/qlm/job/AddUpJob.java
  59. 88 0
      src/main/java/com/qlm/job/CheckYuEJob.java
  60. 426 0
      src/main/java/com/qlm/job/MoveData.java
  61. 60 0
      src/main/java/com/qlm/job/MyJob.java
  62. 20 0
      src/main/java/com/qlm/log/Log.java
  63. 15 0
      src/main/java/com/qlm/log/LogerFactory.java
  64. 106 0
      src/main/java/com/qlm/log/Logger.java
  65. 69 0
      src/main/java/com/qlm/poi/Data.java
  66. 46 0
      src/main/java/com/qlm/poi/ExcelHeader.java
  67. 632 0
      src/main/java/com/qlm/poi/ExcelUtil.java
  68. 249 0
      src/main/java/com/qlm/poi/PoiExcelHelper.java
  69. 74 0
      src/main/java/com/qlm/poi/PoiExcelHelperImpl03.java
  70. 69 0
      src/main/java/com/qlm/poi/PoiExcelHelperImpl07.java
  71. 24 0
      src/main/java/com/qlm/rpc/CacheNotice.java
  72. 23 0
      src/main/java/com/qlm/service/IAdminService.java
  73. 27 0
      src/main/java/com/qlm/service/IAreaHbConfigService.java
  74. 17 0
      src/main/java/com/qlm/service/IAuthService.java
  75. 13 0
      src/main/java/com/qlm/service/IHBRateService.java
  76. 10 0
      src/main/java/com/qlm/service/IOperatingService.java
  77. 12 0
      src/main/java/com/qlm/service/IProductService.java
  78. 14 0
      src/main/java/com/qlm/service/IQrcodeAddService.java
  79. 20 0
      src/main/java/com/qlm/service/IRecordService.java
  80. 20 0
      src/main/java/com/qlm/service/IResService.java
  81. 26 0
      src/main/java/com/qlm/service/IRoleService.java
  82. 26 0
      src/main/java/com/qlm/service/ISearchService.java
  83. 19 0
      src/main/java/com/qlm/service/IStatisticService.java
  84. 17 0
      src/main/java/com/qlm/service/IUnPayInfoService.java
  85. 43 0
      src/main/java/com/qlm/service/TypeServices.java
  86. 75 0
      src/main/java/com/qlm/service/UploadService.java
  87. 54 0
      src/main/java/com/qlm/service/WmesService.java
  88. 244 0
      src/main/java/com/qlm/service/impl/AreaHbConfigServiceImpl.java
  89. 150 0
      src/main/java/com/qlm/service/impl/AuthServiceImpl.java
  90. 69 0
      src/main/java/com/qlm/service/impl/HBRateServiceImpl.java
  91. 95 0
      src/main/java/com/qlm/service/impl/IAdminServiceImpl.java
  92. 43 0
      src/main/java/com/qlm/service/impl/OperatingServiceImpl.java
  93. 24 0
      src/main/java/com/qlm/service/impl/ProductServiceImpl.java
  94. 341 0
      src/main/java/com/qlm/service/impl/QrcodeAddServiceImpl.java
  95. 191 0
      src/main/java/com/qlm/service/impl/RecordServiceImpl.java
  96. 72 0
      src/main/java/com/qlm/service/impl/ResServiceImpl.java
  97. 116 0
      src/main/java/com/qlm/service/impl/RoleServiceImpl.java
  98. 402 0
      src/main/java/com/qlm/service/impl/SearchServiceImpl.java
  99. 153 0
      src/main/java/com/qlm/service/impl/StatisticServiceImpl.java
  100. 0 0
      src/main/java/com/qlm/service/impl/UnPayInfoService.java

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+/target/
+/.checkstyle
+/.classpath
+/.project
+/.settings/

+ 177 - 0
pom.xml

@@ -0,0 +1,177 @@
+<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>jinzai</groupId>
+	<artifactId>jinzai</artifactId>
+	<packaging>war</packaging>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>xyk Maven Webapp</name>
+	<url>http://maven.apache.org</url>
+	<build>
+		<finalName>tmzn</finalName>
+		<plugins>
+			<plugin>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.1</version>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+	</plugins>
+	</build>		
+	<dependencies>
+		<dependency>
+			<groupId>javax.servlet.jsp</groupId>
+			<artifactId>jsp-api</artifactId>
+			<version>2.2</version>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>javax.servlet-api</artifactId>
+			<version>3.1.0</version>
+			<scope>provided</scope>
+		</dependency>
+		  	<dependency>
+			<groupId>com.qiniu</groupId>
+			<artifactId>qiniu-java-sdk</artifactId>
+			<version>7.0.8</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.1.41</version>
+		</dependency>
+
+		<dependency>
+			<groupId>jstl</groupId>
+			<artifactId>jstl</artifactId>
+			<version>1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>com.jfinal</groupId>
+			<artifactId>jfinal</artifactId>
+			<version>2.2</version>
+		</dependency>
+		<dependency>
+			<groupId>com.jfinal</groupId>
+			<artifactId>jfinal-weixin</artifactId>
+			<version>1.5</version>
+		</dependency>
+		<dependency>
+			<groupId>org.freemarker</groupId>
+			<artifactId>freemarker</artifactId>
+			<version>2.3.19</version>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-collections</groupId>
+			<artifactId>commons-collections</artifactId>
+			<version>3.2.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.mybatis</groupId>
+			<artifactId>mybatis</artifactId>
+			<version>3.2.1</version>
+		</dependency>
+		<dependency>
+			<!-- MySQL数据库驱动 -->
+			<groupId>mysql</groupId>
+			<artifactId>mysql-connector-java</artifactId>
+			<version>8.0.16</version>
+		</dependency>
+		<dependency>
+			<groupId>c3p0</groupId>
+			<artifactId>c3p0</artifactId>
+			<version>0.9.1.2</version>
+		</dependency>
+		<dependency>
+		    <groupId>com.alibaba</groupId>
+		    <artifactId>druid</artifactId>
+		    <version>1.1.20</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-pool</groupId>
+			<artifactId>commons-pool</artifactId>
+			<version>20030825.183949</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-fileupload</groupId>
+			<artifactId>commons-fileupload</artifactId>
+			<version>1.2.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.json</groupId>
+			<artifactId>json</artifactId>
+			<version>20080701</version>
+		</dependency>
+		<dependency>
+			<groupId>net.sf.ehcache</groupId>
+			<artifactId>ehcache</artifactId>
+			<version>2.8.1</version>
+		</dependency>
+		<!-- 这里是sl4j的包 -->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>1.7.13</version>
+		</dependency>
+		<dependency>
+			<groupId>ch.qos.logback</groupId>
+			<artifactId>logback-core</artifactId>
+			<version>1.1.3</version>
+		</dependency>
+		<dependency>
+			<groupId>ch.qos.logback</groupId>
+			<artifactId>logback-classic</artifactId>
+			<version>1.1.3</version>
+		</dependency>
+		<dependency>
+			<groupId>com.jfinal</groupId>
+			<artifactId>jfinal-ext2</artifactId>
+			<version>2.0.5</version>
+		</dependency>
+		<dependency>
+			<groupId>org.quartz-scheduler</groupId>
+			<artifactId>quartz</artifactId>
+			<version>2.0.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml</artifactId>
+			<version>3.10-FINAL</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.6</version>
+		</dependency>
+		<dependency>
+		    <groupId>org.apache.ant</groupId>
+		    <artifactId>ant</artifactId>
+		    <version>1.8.2</version>
+		</dependency>
+					<dependency>
+    <groupId>com.google.zxing</groupId>
+    <artifactId>core</artifactId>
+    <version>3.1.0</version>
+</dependency>
+<dependency>
+    <groupId>com.google.zxing</groupId>
+    <artifactId>javase</artifactId>
+    <version>3.1.0</version>
+</dependency>
+<dependency>
+    <groupId>org.jsoup</groupId>
+    <artifactId>jsoup</artifactId>
+    <version>1.14.3</version>
+</dependency>
+	</dependencies>
+</project>

+ 13 - 0
src/main/java/com/qlm/annotation/RequestUrl.java

@@ -0,0 +1,13 @@
+package com.qlm.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+/**运行时注解*/
+@Target({ElementType.TYPE, ElementType.METHOD})
+public @interface RequestUrl {
+	String value();
+}

+ 14 - 0
src/main/java/com/qlm/common/Define.java

@@ -0,0 +1,14 @@
+package com.qlm.common;
+
+public class Define {
+	public static final int ADD_QRCODE_MAX = 5000000;//最大产码数量
+	public static final int ADD_QRCODE_IMG_MAX = 100000;//最大产码图片数量
+	public static final int ADD_QRCODE_MIN = 1;//最小产码数量
+	public static final int QRCODE_MAX = 100000000;//产码分表数量
+	public static final int ADD_QRCODE_SINGLE = 2500000;//产码分包数量
+	public final static int  QRCODE_LENGTH = 15;//链接参数长度
+	//角色
+	public final static int ROLE_ADMIN = 1;//管理员
+	public final static int ROLE_MANAGE = 2;//超级管理员
+	public final static int ROLE_DEVELOP = 3;//开发者
+}

+ 128 - 0
src/main/java/com/qlm/controller/AuthController.java

@@ -0,0 +1,128 @@
+package com.qlm.controller;
+
+import java.util.regex.Pattern;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.service.IAuthService;
+import com.qlm.service.impl.AuthServiceImpl;
+import com.qlm.tools.MyCaptchaRender;
+import com.qlm.view.core.AdminView;
+
+public class AuthController extends Controller {
+	protected final static Logger logger = LoggerFactory
+			.getLogger(AuthController.class);
+
+	private IAuthService adminService = enhance(AuthServiceImpl.class);
+
+	// 用户名正则
+	private static final String REGEX = "^[a-zA-Z0-9]+$";
+
+	/**
+	 * 登陆处理
+	 */
+	public void login() {
+		getSession().invalidate();
+		AdminView adminView = getBean(AdminView.class, "adminView");
+		String username = adminView.getUsername();
+		readLogoInfo();
+		if (username == null || adminView.getPassword() == null) {
+			render("/page/login.jsp");
+			return;
+		}
+		Pattern p = Pattern.compile(REGEX);
+		boolean flg = p.matcher(username).matches();
+		if (!flg) {
+			setSessionAttr("message", "用户名中包含非法字符");
+			render("/page/login.jsp");
+			return;
+		}
+
+		String inputRandomCode = getPara("captcha");
+		boolean validate = MyCaptchaRender.validate(this, inputRandomCode);
+		if (!validate) {
+			setSessionAttr("message", "验证码有误");
+			render("/page/login.jsp");
+			return;
+		}
+		AdminView admin = adminService.login(adminView);
+		if(admin==null) {
+			setSessionAttr("message", "密码有误");
+			render("/page/login.jsp");
+		}else if (admin != null && admin.getStatus()==0) {
+			setSessionAttr("message", "用户被禁用,请联系超级管理员!");
+			render("/page/login.jsp");
+		} else {
+			setSessionAttr("adminView", admin);
+			redirect("/index");
+		}
+	}
+
+	public void index() {// 没登录时,不能到index页面要返回到登录页面
+		AdminView admin = getSessionAttr("adminView");
+		readLogoInfo();
+		if (admin != null) {
+			String menus = adminService.getMenuByUserId(admin,getRequest().getContextPath());
+			setAttr("menus",menus);
+			render("/page/menu.jsp");
+		} else {
+			render("/page/login.jsp");
+		}
+
+	}
+
+	private void readLogoInfo() {
+		Record loginLogo = Db.findFirst("select * from t_config where key_ = ?","loginLogo");
+		Record logoConfig = Db.findFirst("select * from t_config where key_ = ?","logo");
+		Record company = Db.findFirst("select * from t_config where key_ = ?","companyName");
+		Record info = new Record();
+		info.set("logo", logoConfig.getStr("value_"))
+		.set("name", company.getStr("value_")).set("loginLogo", loginLogo.get("value_"));
+		setAttr("info", info);
+	}
+
+	/**
+	 * 退出处理
+	 */
+	public void logout() {
+		getSession().invalidate();
+		render("/page/login.jsp");
+	}
+
+	/**
+	 * 原密码验证
+	 */
+	@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+	public void pwdCheck() {
+		AdminView av = getSessionAttr("adminView");
+		boolean flg = adminService.pwdCheck(av.getUsername(),
+				getPara("oldPassword"));
+		if (flg) {
+			renderText("success");
+		}
+	}
+
+	/**
+	 * 修改密码
+	 */
+	@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+	public void updPwd() {
+		AdminView av = getSessionAttr("adminView");
+		AdminView adminView = new AdminView();
+		adminView.setId(av.getOriginId());
+		adminView.setOldPwd(getPara("oldPwd"));
+		adminView.setPassword(getPara("newPwd"));
+		renderJson(adminService.adminUpd(adminView));
+	}
+
+	public void AuthImage() {
+		render(new MyCaptchaRender(100, 34, 4, true));
+	}
+}

+ 8 - 0
src/main/java/com/qlm/controller/FeedBackController.java

@@ -0,0 +1,8 @@
+package com.qlm.controller;
+
+import com.jfinal.aop.Before;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AuthInterceptor;
+@Before(AuthInterceptor.class)
+public class FeedBackController extends CommonController {
+}

+ 44 - 0
src/main/java/com/qlm/controller/HBRateController.java

@@ -0,0 +1,44 @@
+package com.qlm.controller;
+
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.HBRate;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.rpc.CacheNotice;
+import com.qlm.service.IHBRateService;
+import com.qlm.service.IProductService;
+import com.qlm.service.impl.HBRateServiceImpl;
+import com.qlm.service.impl.ProductServiceImpl;
+import com.qlm.tools.Common;
+import com.qlm.view.ResultMsg;
+
+@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+public class HBRateController extends Controller {
+
+	private IHBRateService hbrateService = enhance(HBRateServiceImpl.class);
+	
+	private IProductService productService = enhance(ProductServiceImpl.class);
+	
+	public void getHbrate(){				
+//		Integer type = getParaToInt("type") == null?0:getParaToInt("type");
+//		List<HBRate> view = hbrateService.getHBRateList(type);
+//		setAttr("scanView", view);
+//		setAttr("type", type);
+//		List<Record> productList = productService.getProductInfoList();
+//		setAttr("productList", productList);
+//		renderJsp("/page/hbrate0.jsp");
+	}
+	
+	public void saveHbrate(){
+//		String[] money_ = getParaValues("money");
+//		String[] rate_ = getParaValues("rate");
+//		Integer type_ = getParaToInt("type");
+//		ResultMsg rm = hbrateService.saveHbrate(money_, rate_, type_);
+//		CacheNotice.updateScan();
+//		renderJson(rm);
+	}
+}

+ 87 - 0
src/main/java/com/qlm/controller/IndexController.java

@@ -0,0 +1,87 @@
+package com.qlm.controller;
+
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.ehcache.CacheKit;
+import com.jfinal.plugin.ehcache.IDataLoader;
+import com.qlm.common.Define;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.tools.Common;
+import com.qlm.tools.DateUtils;
+import com.qlm.view.SummaryView;
+
+@Before(AuthInterceptor.class)
+public class IndexController extends Controller{
+	protected final static Logger logger = LoggerFactory.getLogger(IndexController.class);
+
+	public static SummaryView summary = null;
+	
+	//红包金额(元/分)转换中间值
+	public final static BigDecimal HB_AMOUNT = new BigDecimal(100);
+	
+	@Before(AdminOperate2Interceptor.class)
+	public void mainPage(){
+		logger.info("method:mainPage");
+//		SummaryView view  = new SummaryView();
+//		long yesterday_scan_num = 0;
+//		long total_user_num = 0;
+//		long total_qrcode_num = 0;
+//		long total_scan_num = 0;
+//		BigDecimal total_amount = new BigDecimal(0);
+//		BigDecimal yesterday_amount = new BigDecimal(0);
+//		String yesterday = DateUtils.dateToString(DateUtils.addDay(new Date(), -1), DateUtils.PATTEN_HMS);
+//			
+//		//获取产码表名
+//		String sql = "select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='wzz' and TABLE_NAME like 't_qrcode__' ";
+//		List<Record> recordList = Db.find(sql);
+//		//获取扫码用户表数量
+//		total_user_num = Db.queryLong("select IFNULL(count(id),0) from t_god ");
+//		
+//		if(!Common.isNullOrEmpty(recordList) && recordList.size() != 0){
+//			//查询已产码数量
+//			String qrcodeSql = "select IFNULL(count(id),0) from ";
+//			//产码已扫描数量及已发放红包总金额
+//			String scanSql = "select  IFNULL(count(qrcode_id),0) totalScan from ";			
+//			//遍历产码表名
+//			for(Record r : recordList){
+//				//查询昨日扫描数量及昨日发放红包总金额
+//				String yesScanSql = "select IFNULL(count(id),0) totalYesScan,IFNULL(SUM(hb_amount),0) totalYesAmount from "+r.getStr("TABLE_NAME")+"_scan "+" where DATE_FORMAT(scan_time,'%Y-%m-%d') =DATE_FORMAT('"+yesterday+"','%Y-%m-%d')";
+//				
+//				total_qrcode_num += Db.queryLong(qrcodeSql+r.getStr("TABLE_NAME"));
+//				String scan = scanSql+r.getStr("TABLE_NAME")+"_scan ";
+//				Record scanRecord = Db.findFirst(scan);
+//				if(!Common.isNullOrEmpty(scanRecord)){
+//					total_scan_num += scanRecord.getLong("totalScan");
+//					total_amount = total_amount.add(scanRecord.getBigDecimal("totalAmount"));
+//				}
+//				Record yesRecord = Db.findFirst(yesScanSql);
+//				if(!Common.isNullOrEmpty(yesRecord)){
+//					yesterday_scan_num += yesRecord.getLong("totalYesScan");
+//					yesterday_amount = yesterday_amount.add(yesRecord.getBigDecimal("totalYesAmount"));					
+//				}
+//			}
+//			view.setTotal_amount(total_amount.divide(HB_AMOUNT)); 
+//			view.setTotal_qrcode_num(total_qrcode_num);
+//			view.setTotal_scan_num(total_scan_num);
+//			view.setTotal_user_num(total_user_num);
+//			view.setYesterday_amount(yesterday_amount.divide(HB_AMOUNT));
+//			view.setYesterday_scan_num(yesterday_scan_num);
+//		}
+//		
+//		setAttr("summary", view);
+		render("/page/index.jsp");
+	}
+
+}

+ 32 - 0
src/main/java/com/qlm/controller/OperatingController.java

@@ -0,0 +1,32 @@
+package com.qlm.controller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IOperatingService;
+import com.qlm.service.impl.OperatingServiceImpl;
+
+@Before(AuthInterceptor.class)
+public class OperatingController extends Controller{
+	protected final static Logger logger = LoggerFactory.getLogger(OperatingController.class);
+	
+	IOperatingService operatingService = enhance(OperatingServiceImpl.class);
+	/**
+	 * 操作日志记录页面
+	 */
+	  public void listOperatingSkip(){
+		  render("/page/logList.jsp");
+	  }
+	  
+		/**
+		 * 操作日志记录数据获取
+		 */
+	  public void listOperating(){
+		  String aoData = getPara("aoData");
+		  String jsonStr = operatingService.OperatingRecordList(aoData);
+		  renderJson(jsonStr); 
+	  }
+}

+ 35 - 0
src/main/java/com/qlm/controller/UploadController.java

@@ -0,0 +1,35 @@
+package com.qlm.controller;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.aop.Clear;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.service.UploadService;
+import com.qlm.tools.WxUtil;
+
+@RequestUrl("/upload")
+public class UploadController extends Controller {
+	UploadService uploadService = enhance(UploadService.class);
+	@Clear
+	public void uploadData(){
+		
+		Record result = new Record();
+		
+		String data = getPara("data");
+		uploadService.upload(data);
+		result.set("status", true);
+		renderJson(result);
+	}
+
+}

+ 304 - 0
src/main/java/com/qlm/controller/common/CommonController.java

@@ -0,0 +1,304 @@
+package com.qlm.controller.common;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.List;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+@Before(AuthInterceptor.class)
+public class CommonController extends Controller{
+
+		/**
+		 * 返回对应的列表页面
+		 * @param key
+		 * @return
+		 */
+		protected String getPath(String key) {
+			return "";
+		}
+
+		protected Record saveByTable(String tableName) {
+			return null;
+		}
+		
+		public void save(){
+			String key = getPara("pri_key","id");
+			String tableName = getPara("key");
+			Record saveByTable = saveByTable(tableName);
+			if(saveByTable != null){
+				renderJson(saveByTable);
+				return;
+			}
+			Enumeration enu=getRequest().getParameterNames();  
+			Record result = new Record();
+			Record record = new Record();
+			String ignoreCol = getPara("ignoreCol");
+			String [] ignoreCols = new String[]{};
+			if(!WxUtil.isNull(ignoreCol)){
+				ignoreCols= ignoreCol.split(",");
+			}
+			while(enu.hasMoreElements()){  
+			String paraName=(String)enu.nextElement();  
+				String value = getPara(paraName);
+				if("pri_key".equals(paraName)){
+					continue;
+				}
+				if("key".equals(paraName)){
+					continue;
+				}
+				if("paramConfig".equals(paraName)){
+					continue;
+				}
+				if(containCol(paraName,ignoreCols)){
+					continue;
+				}
+				record.set(paraName, value);
+			} 
+			beforeSave(tableName,record);
+			try{
+				checkData(tableName,record);
+			}catch(Exception e){
+				e.printStackTrace();
+				result.set("status", false);
+				result.set("msg", e.getMessage());
+				renderJson(result);
+				return;
+			}
+			try{
+				record.set("create_time", new Date());
+				Db.save(tableName,key,record);
+			}catch(Exception e){
+				e.printStackTrace();
+				record.remove("create_time");
+				Db.save(tableName,key,record);
+			}
+			Record findById = Db.findById(tableName,key, record.get(key));
+			afterSave(tableName, findById);
+			result.set("status", true);
+			result.set("data", findById);
+			renderJson(result);
+		}
+		
+	protected void beforeSave(String tableName,Record data){
+			
+		}
+	protected void checkData(String tableName,Record data){
+		
+	}
+		
+		/**
+		 * 返回数据库对应的表名
+		 * @param key 表名
+		 * @return
+		 */
+		protected String getTableName(String key){
+			return key;
+		}
+
+		public void list(){
+			String key = getPara("key");
+			setAttr("tableName", getTableName(key));
+			Enumeration enu=getRequest().getParameterNames();  
+			while(enu.hasMoreElements()){  
+			String paraName=(String)enu.nextElement();  
+				String value = getPara(paraName);
+				if("key".equals(paraName)){
+					continue;
+				}
+				setAttr(paraName, value);
+			}
+			setData();
+			render(getPath(key));
+		}
+		
+		/**
+		 * 在列表里面增加一些新的数据传递
+		 */
+		protected void setData() {
+			// TODO Auto-generated method stub
+			
+		}
+
+		protected Record getData(String tableName,int pageStart,int pageSize) {
+			return null;
+		}
+		
+		public void query(){
+			int pageSize = getParaToInt("pageSize",10);
+			int page = getParaToInt("pageNumber",1);
+			int pageStart = pageSize*(page-1);
+			String tableName = getPara("key");
+			String order = getPara("order");
+			String toolBarConfig = getPara("toolBarConfig");
+			String whereSql = "";
+			List<String> conditions = new ArrayList<String>();
+			if(!WxUtil.isNull(toolBarConfig)){
+				JSONArray parseArray = JSONArray.parseArray(toolBarConfig);
+				for (int i = 0; i < parseArray.size(); i++) {
+					JSONObject jsonObject = parseArray.getJSONObject(i);
+					String nameKey = jsonObject.getString("key");
+					String type = jsonObject.getString("type");
+					String para = getPara(nameKey);
+					if(WxUtil.isNull(para) || "all".equals(para)){
+						continue;
+					}
+					if(whereSql.length()>0){
+						whereSql+= " and ";
+					}else{
+						whereSql+= " where ";
+					}
+					if("input".equals(type)){
+						whereSql += " "+nameKey+" like '%"+para+"%'";	
+					}else if("select".equals(type)){
+						whereSql += " "+nameKey+" =? ";
+						conditions.add(para);
+					}
+					
+					
+				}
+			}
+			String paramConfig = getPara("paramConfig");
+			if(!WxUtil.isNull(paramConfig)){
+				String [] paramConfigs = paramConfig.split(";");
+				for (String extraConfig : paramConfigs) {
+					String[] values = extraConfig.split("=");
+					String pName = values[0];
+					if(whereSql.length()>0){
+						whereSql+= " and "+pName+"= ? ";
+					}else{
+						whereSql+= " where "+pName+"= ? ";;
+					}
+					conditions.add(values[1]);
+				}
+				
+			}
+			Record data = getData(tableName,pageStart,pageSize);
+			Long queryLong = null;
+			List<Record> find = null;
+			if(data != null){
+				queryLong = data.getLong("total");
+				find = data.get("list");
+			}else{
+				String[] array = conditions.toArray(new String[conditions.size()]);
+				if(conditions.isEmpty()){
+					queryLong = Db.queryLong("select count(*) from "+tableName+" "+whereSql);
+				}else{
+					queryLong = Db.queryLong("select count(*) from "+tableName+" "+whereSql,array);
+				}
+			
+				String sql = "";
+				if(!WxUtil.isNull(order)){
+					sql = "select * from "+tableName +" "+" "+whereSql+" "+order+" limit "+pageStart+","+pageSize;
+				}else{
+					sql = "select * from "+tableName +" "+whereSql+"  limit "+pageStart+","+pageSize;
+				}
+				if(conditions.isEmpty()){
+					 find = Db.find(sql);
+				}else{
+					 find = Db.find(sql,array);
+				}
+				
+			}
+			formatData(tableName,find);
+			Record r = new Record();
+			r.set("rows", find);
+			r.set("total", queryLong);
+			renderJson(r);
+		}
+		
+		protected  void formatData(String tableName, List<Record> find) {
+			// TODO Auto-generated method stub
+			
+		}
+
+		public void getById(){
+			String key = getPara("pri_key","id");
+			String id = getPara("id");
+			String tableName = getPara("key");
+			Record findById = Db.findById(tableName,key, id);
+			renderJson(findById);
+		}
+		
+		public void edit(){
+			String key = getPara("pri_key","id");
+			Enumeration enu=getRequest().getParameterNames();  
+			Record result = new Record();
+			Record record = new Record();
+			String tableName = getPara("key");
+			String id = getPara(key);
+			Record data = Db.findById(tableName,key, id);
+			String ignoreCol = getPara("ignoreCol");
+			String [] ignoreCols = new String[]{};
+			if(!WxUtil.isNull(ignoreCol)){
+				ignoreCols= ignoreCol.split(",");
+			}
+			String[] columnNames = data.getColumnNames();
+			while(enu.hasMoreElements()){  
+			String paraName=(String)enu.nextElement();  
+				String value = getPara(paraName);
+				if(!containCol(paraName,columnNames)){
+					continue;
+				}
+				if(containCol(paraName,ignoreCols)){
+					continue;
+				}
+				if("paramConfig".equals(paraName)){
+					continue;
+				}
+				record.set(paraName, value);
+			} 
+			try{
+				checkData(tableName,record);
+			}catch(Exception e){
+				e.printStackTrace();
+				result.set("status", false);
+				result.set("msg", e.getMessage());
+				renderJson(result);
+				return;
+			}
+			Db.update(tableName,key,record);
+			Record findById = Db.findById(tableName,key, record.get(key));
+			result.set("status", true);
+			result.set("data", findById);
+			renderJson(result);
+		}
+		
+		protected boolean containCol(String colName,String []arr){
+			for (String string : arr) {
+				if(colName.equals(string)){
+					return true;
+				}
+			}
+			return false;
+		}
+		public void del(){
+			String key = getPara("pri_key","id");
+			String id = getPara(key);
+			String tableName = getPara("key");
+			Db.deleteById(tableName, key, id);
+			afterDel(tableName,id);
+			Record result = new Record();
+			result.set("status", true);
+			renderJson(result);
+		}
+		
+		protected void afterSave(String tableName,Record data) {
+		}
+		protected void afterDel(String tableName,String id) {
+			
+		}
+		protected AdminView getLoginUser() {
+			AdminView admin = getSessionAttr("adminView");
+			return admin;
+		}
+		
+}

+ 138 - 0
src/main/java/com/qlm/controller/common/CommonUserController.java

@@ -0,0 +1,138 @@
+package com.qlm.controller.common;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.List;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+
+public class CommonUserController extends CommonController{
+
+	public void query(){
+		int pageSize = getParaToInt("pageSize",10);
+		int page = getParaToInt("pageNumber",1);
+		int pageStart = pageSize*(page-1);
+		String tableName = getPara("key");
+		String order = getPara("order");
+		String toolBarConfig = getPara("toolBarConfig");
+		String whereSql = "";
+		List<String> conditions = new ArrayList<String>();
+		if(!WxUtil.isNull(toolBarConfig)){
+			JSONArray parseArray = JSONArray.parseArray(toolBarConfig);
+			for (int i = 0; i < parseArray.size(); i++) {
+				JSONObject jsonObject = parseArray.getJSONObject(i);
+				String nameKey = jsonObject.getString("key");
+				String type = jsonObject.getString("type");
+				String para = getPara(nameKey);
+				if(WxUtil.isNull(para) || "all".equals(para)){
+					continue;
+				}
+				if(whereSql.length()>0){
+					whereSql+= " and ";
+				}else{
+					whereSql+= " where ";
+				}
+				if("input".equals(type)){
+					whereSql += " "+nameKey+" like '%"+para+"%'";	
+				}else if("select".equals(type)){
+					whereSql += " "+nameKey+" =? ";
+					conditions.add(para);
+				}
+				
+				
+			}
+		}
+		Record data = getData(tableName,pageStart,pageSize);
+		Long queryLong = null;
+		List<Record> find = null;
+		AdminView loginUser = getLoginUser();
+		int uid = loginUser.getId();
+		if(data != null){
+			queryLong = data.getLong("total");
+			find = data.get("list");
+		}else{
+			if(!WxUtil.isNull(whereSql)){
+				whereSql += " and uid = "+uid+" ";
+			}else{
+				whereSql += " where uid = "+uid+" ";
+			}
+			String[] array = conditions.toArray(new String[conditions.size()]);
+			if(conditions.isEmpty()){
+				queryLong = Db.queryLong("select count(*) from "+tableName+" "+whereSql);
+			}else{
+				queryLong = Db.queryLong("select count(*) from "+tableName+" "+whereSql,array);
+			}
+		
+			String sql = "";
+			if(!WxUtil.isNull(order)){
+				sql = "select * from "+tableName +" "+" "+whereSql+" "+order+" limit "+pageStart+","+pageSize;
+			}else{
+				sql = "select * from "+tableName +" "+whereSql+"  limit "+pageStart+","+pageSize;
+			}
+			if(conditions.isEmpty()){
+				 find = Db.find(sql);
+			}else{
+				 find = Db.find(sql,array);
+			}
+			
+		}
+		
+		Record r = new Record();
+		r.set("rows", find);
+		r.set("total", queryLong);
+		renderJson(r);
+	}
+	
+	
+	public void save(){
+		String key = getPara("pri_key","id");
+		String tableName = getPara("key");
+		Record saveByTable = saveByTable(tableName);
+		if(saveByTable != null){
+			renderJson(saveByTable);
+			return;
+		}
+		Enumeration enu=getRequest().getParameterNames();  
+		Record result = new Record();
+		Record record = new Record();
+		String ignoreCol = getPara("ignoreCol");
+		String [] ignoreCols = new String[]{};
+		if(!WxUtil.isNull(ignoreCol)){
+			ignoreCols= ignoreCol.split(",");
+		}
+		while(enu.hasMoreElements()){  
+		String paraName=(String)enu.nextElement();  
+			String value = getPara(paraName);
+			if("pri_key".equals(paraName)){
+				continue;
+			}
+			if("key".equals(paraName)){
+				continue;
+			}
+			if(containCol(paraName,ignoreCols)){
+				continue;
+			}
+			record.set(paraName, value);
+		} 
+		beforeSave(tableName,record);
+		try{
+			AdminView loginUser = getLoginUser();
+			record.set("create_time", new Date()).set("uid", loginUser.getId());
+			Db.save(tableName,key,record);
+		}catch(Exception e){
+			e.printStackTrace();
+			record.remove("create_time");
+			Db.save(tableName,key,record);
+		}
+		Record findById = Db.findById(tableName,key, record.get(key));
+		result.set("status", true);
+		result.set("data", findById);
+		renderJson(result);
+	}
+}

+ 27 - 0
src/main/java/com/qlm/controller/core/AreaController.java

@@ -0,0 +1,27 @@
+package com.qlm.controller.core;
+
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonUserController;
+@RequestUrl("/area")
+public class AreaController extends CommonUserController{
+
+	
+	
+	@Override
+	protected String getTableName(String key) {
+		// TODO Auto-generated method stub
+		return "t_area";
+	}
+
+	@Override
+	protected String getPath(String key) {
+		// TODO Auto-generated method stub
+		return "/page/t_area/index.jsp";
+	}
+	
+	
+	
+	
+	
+	
+}

+ 25 - 0
src/main/java/com/qlm/controller/core/ConfigController.java

@@ -0,0 +1,25 @@
+package com.qlm.controller.core;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.controller.common.CommonUserController;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.TypeServices;
+
+@RequestUrl("/config")
+public class ConfigController extends CommonUserController{
+	@Override
+	protected String getTableName(String key) {
+		// TODO Auto-generated method stub
+		return "t_config";
+	}
+
+	@Override
+	protected String getPath(String key) {
+		// TODO Auto-generated method stub
+		return "/page/t_config/index.jsp";
+	}
+}

+ 329 - 0
src/main/java/com/qlm/controller/core/ProduceController.java

@@ -0,0 +1,329 @@
+package com.qlm.controller.core;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.HttpKit;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.kit.PropKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonUserController;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+@RequestUrl("/produce")
+public class ProduceController extends CommonUserController{
+	private static final Logger logger = LoggerFactory.getLogger(ProduceController.class);
+	public void pici(){
+		AdminView loginUser = getLoginUser();
+		int id = loginUser.getId();
+		List<Record> find = Db.find("select * from t_product where uid = ?",id);
+		setAttr("products", JsonKit.toJson(find));
+		render("/page/produce/pici.jsp");
+	}
+
+	public void jinyongPici(){
+		int id = getParaToInt("id");
+		int status = getParaToInt("status");
+		ResultMsg msg = new ResultMsg();
+		Db.update("update t_pici set status = ? where id = ?",status,id);
+		msg.setStatus(true);
+		renderJson(msg);
+	}
+	
+	public void piciById(){
+		int id = getParaToInt("id");
+		Record findById = Db.findById("t_pici", id);
+		renderJson(findById);
+	}
+
+	public void updatePici(){
+		String name = getPara("name_");
+		String price = getPara("price");
+		String scale = getPara("scale");
+		String product = getPara("product");
+		String id = getPara("id");
+		Db.update("update t_pici set pici = ?,price = ?,scale = ?,product_type  = ? where id =?",name,price,scale,product,id);
+		ResultMsg msg = new ResultMsg();
+		Record findById = Db.findById("t_pici", id);
+		msg.set("product",findById);
+		msg.setStatus(true);
+		renderJson(msg);
+	}
+	
+	public void addPici(){
+		AdminView loginUser = getLoginUser();
+		int id = loginUser.getId();
+		String name = getPara("name_");
+		String price = getPara("price");
+		String scale = getPara("scale");
+		String product = getPara("product");
+		Record info  =new Record();
+		info.set("pici", name).set("create_time", new Date()).set("status", 1)
+		.set("price", price).set("scale", scale).set("product_type", product).set("uid", id);
+		Db.save("t_pici", info);
+		ResultMsg msg = new ResultMsg();
+		msg.set("product",info);
+		msg.setStatus(true);
+		renderJson(msg);
+	}
+	
+	public void piciQuery(){
+		AdminView loginUser = getLoginUser();
+		int id = loginUser.getId();
+		List<Record> find = Db.find("select t.*,p.name_ from t_pici t left join t_product p on(t.product_type = p.type_) where t.uid = "+id+" order by create_time desc");
+		renderJson(find);
+	}
+
+	public void info(){
+		AdminView loginUser = getLoginUser();
+		int id = loginUser.getId();
+		List<Record> find = Db.find("select * from t_pici where status = 1 and uid = ?",id);
+		setAttr("piciList", find);
+		render("/page/produce/masterInfo.jsp");
+	}
+	
+	public void setInfo(){
+		
+	}
+	
+	public void infoQuery(){
+		String date = getPara("startDate");
+		String pici = getPara("pici");
+		List<Record> list = null;
+		if("all".equals(pici)){
+			list = Db.find("select m.*,p.pici,a.area_name from t_master m left join t_pici p on(m.pici_id = p.id) left join t_area a on(m.area_id = a.id) where date(send_time) = ?",date);
+		}else{
+			list = Db.find("select m.*,p.pici,a.area_name from t_master m left join t_pici p on(m.pici_id = p.id) left join t_area a on(m.area_id = a.id) where date(send_time) = ? and pici_id = ?",date,pici);	
+		}
+		Map<String,Record> maps = new HashMap<String, Record>();
+		StringBuilder sb = new StringBuilder();
+		for (Record record : list) {
+			String master_code = record.getStr("master_code");
+			if(sb.length()>0){
+				sb.append(",");
+			}
+			sb.append("'"+master_code+"'");
+			maps.put(master_code, record);
+		}
+		if(sb.length()>0){
+			List<Record> find = Db.find("select count(*) c,master_code from t_qcode_a where master_code in ("+sb+") group by master_code");
+			
+			for (Record record : find) {
+				Integer c = WxUtil.getInt("c", record);
+				String masterCodes = record.getStr("master_code");
+				maps.get(masterCodes).set("count_num", c);
+			}
+		}
+		renderJson(list);
+	}
+	
+	public void infoById(){
+		String masterCode = getPara("masterCode");
+		Record t_masterRecord = Db.findById("t_master", "master_code", masterCode);
+		renderJson(t_masterRecord);
+	}
+	public void updateInfo(){
+		String masterCode = getPara("masterCode");
+		String scale = getPara("scale");
+		String price = getPara("price");
+		int update = Db.update("update t_master set product_price = ?,product_scale = ? where master_code = ?",price,scale,masterCode);
+		Record t_masterRecord = Db.findById("t_master", "master_code", masterCode);
+		ResultMsg msg = new ResultMsg();
+		msg.set("product",t_masterRecord);
+		msg.setStatus(true);
+		
+		renderJson(msg);
+	}
+	
+	public void ywyRecord(){
+		List<Record> ywyList = Db.find("select * from t_ywy ");
+		setAttr("ywyList", ywyList);
+		
+		List<Record> retailList = Db.find("select * from t_retail ");
+		setAttr("retailList", retailList);
+		render("/page/produce/ywyRecord.jsp");
+	}
+	
+	public void ywyRecordQuery(){
+		int pageSize = getParaToInt("pageSize",10);
+		int pageNumber = getParaToInt("pageNumber",1);
+		int pageStart = (pageNumber-1)*pageSize;
+		String ywy = getPara("ywy");
+		String retail = getPara("retail");
+		String retailSql = "";
+		String querySql = "";
+		if(!"all".equals(ywy)){
+			querySql = " where ywy_id = '"+ywy+"' ";
+		}
+		if(!"all".equals(retail)){
+			if(querySql.length()>0){
+				querySql += " and retail_id = '"+retail+"'";
+			}else{
+				querySql = " where retail_id = '"+retail+"'";
+			}
+		}
+		
+		List<Record> find = Db.find("select * from t_ywy_record "+querySql+" order by create_time desc limit "+pageStart+","+pageSize);
+		Record row = new Record();
+		row.set("rows", find);
+		row.set("total", Db.queryLong("select count(*) from t_ywy_record "+querySql.toString()));
+		renderJson(row);
+	}
+	
+	public void detail(){
+		int id= getParaToInt("id");
+		setAttr("id", id);
+		render("/page/produce/ywyRecordDetail.jsp");
+	}
+	public void detailQuery(){
+		int id= getParaToInt("id");
+		List<Record> find = Db.find("select * from t_ywy_record_detail  where record_id = ?",id);
+		StringBuilder sb = new StringBuilder();
+		Map<String,Record> map = new HashMap<String, Record>();
+		for (Record record : find) {
+			String str = record.getStr("code_");
+			if(sb.length()>0){
+				sb.append(",");
+			}
+			sb.append("'"+str+"'");
+			map.put(str, record);
+		}
+		if(sb.length()>0){
+			List<Record> list = Db.find("select * from t_qcode_a where id in ("+sb+")");
+			for (Record record : list) {
+				Object num_ = record.get("num_");
+				String qrcodeId = record.getStr("id");
+				String master_code = record.getStr("master_code");
+				map.get(qrcodeId).set("num_", num_).set("master_code", master_code);
+			}
+		}
+		renderJson(find);
+	}
+	
+	public void jihuo(){
+		List<Record> find = Db.find("select * from t_product");
+		setAttr("productList", find);
+		
+		List<Record> quyuList = Db.find("select * from t_area");
+		setAttr("quyuList", quyuList);
+		
+		
+		List<Record> ywyList = Db.find("select id,nick_name name from t_ywy");
+		setAttr("ywyList", JsonKit.toJson(ywyList));
+		
+		List<Record> retailList = Db.find("select id,retail_name name from t_retail");
+		setAttr("retailList", JsonKit.toJson(retailList));
+		
+		render("/page/produce/jihuo.jsp");
+	}
+	
+	public void doJihuo(){
+		String masterCode = getPara("masterCode");
+		String ywy = getPara("ywy");
+		Record ywyInfo = Db.findById("t_ywy", ywy);
+		String ywyName = ywyInfo.getStr("nick_name");
+		
+		String retail = getPara("retail");
+		
+		Record t_retail = Db.findById("t_retail", retail);
+		String retail_name = t_retail.getStr("retail_name");
+		Record info = new Record();
+		info.set("ywy_id", ywy).set("retail_id", retail).set("ywy_name", ywyName).set("retail_name", retail_name);
+		Db.update("update t_master set info = ? where master_code = ?",JsonKit.toJson(info),masterCode);
+		Db.update("update t_qcode_a set ywy_id = ? ,retail_id = ? where master_code = ?",ywy,retail,masterCode);
+		Record result = new Record();
+		doCallBack(masterCode);
+		result.set("status", true);
+		renderJson(result);
+	}
+	
+	public static void pullMSg(String masterCode){
+		Record masterInfo = Db.findFirst("select * from t_master where master_code = ?",masterCode);
+		String product_scale = masterInfo.getStr("product_scale");
+		String product_price = masterInfo.getStr("product_price");
+		Date date = masterInfo.getDate("send_time");
+		
+		SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMdd");
+		String format = sdf.format(date);
+		List<Record> list = new ArrayList<Record>();
+		List<Record> find = Db.find("select * from t_qcode_a where master_code = ?",masterCode);
+		for (Record record : find) {
+			Record info = new Record();
+			String id = record.getStr("id");
+			Integer ywy_id = WxUtil.getInt("ywy_id", record);
+			Integer retail_id = WxUtil.getInt("retail_id", record);
+			Integer distributorId = WxUtil.getInt("area_id", record);
+			Integer productId = WxUtil.getInt("type_", record);
+			String pici = format+productId;
+			Record findById = Db.findById("t_area", distributorId);
+			String areaName = findById.getStr("name_");
+			Record findFirst = Db.findFirst("select name_ from t_product where type_ = ?",productId);
+			String productName = findFirst.getStr("name_");
+			char charAt = id.charAt(0);
+			Integer number = WxUtil.getInt("num_", record);
+			String suffix =  number.toString();
+			int length = 8 - suffix.length();
+			for (int k = 0; k < length; k++) {
+				suffix = "0" + suffix;
+			}
+			String allNumber = charAt+""+suffix;
+			
+			info.set("distributorId", distributorId)
+			.set("salesmanId", ywy_id).set("productId", productId)
+			.set("shopId", retail_id).set("batchNo", pici)
+			.set("codeNumber", allNumber).set("masterNumber", masterCode)
+			.set("codeId", id).set("codeUrl", "https://j.dnzc.vip/j/"+id)
+			.set("productName", productName).set("productDay", format)
+			.set("productPrice", product_price).set("productScale", product_scale)
+			.set("areaName", areaName).set("sourceType", 2);
+			list.add(info);
+		}
+		Map<String, String> headers=  new HashMap<String, String>();
+		headers.put("token",  "0fc6b6c3b03da9c6f83e515942163519");
+		headers.put("source",  "tianmu");
+		headers.put("Content-Type","application/json");
+		String post = HttpKit.post("https://wyywy.hunanwangyou.com/external/merchandise/code/syn", JsonKit.toJson(list),headers);
+		logger.info(masterCode+","+post);
+		
+	}
+	private void doCallBack(String masterCode) {
+			new Thread(new Runnable() {
+			
+			@Override
+			public void run() {
+				pullMSg(masterCode);
+			}
+		}).start();
+	}
+
+	public void jihuoQuery(){
+		String date = getPara("startDate");
+		String type = getPara("type");
+		String areaId = getPara("areaId");
+		List<Record> list = null;
+		String whereSql = "";
+		
+		if(!"all".equals(type)){
+			whereSql += " and m.type_ = "+type ;
+		}
+		if(!"all".equals(areaId)){
+			whereSql += " and m.area_id = "+areaId ;
+		}
+		list = Db.find("select m.*,a.area_name,p.name_ from t_master m left join t_product p on(m.type_ = p.type_) left join t_area a on(m.area_id = a.id) where date(send_time) = ? "+whereSql,date);	
+		renderJson(list);
+	}
+}

+ 71 - 0
src/main/java/com/qlm/controller/core/QrcodeAddController.java

@@ -0,0 +1,71 @@
+package com.qlm.controller.core;
+
+import java.io.File;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IProductService;
+import com.qlm.service.IQrcodeAddService;
+import com.qlm.service.impl.ProductServiceImpl;
+import com.qlm.service.impl.QrcodeAddServiceImpl;
+import com.qlm.view.core.AdminView;
+@RequestUrl("qrCodeAdd")
+public class QrcodeAddController extends CommonController{
+	
+	private static final Logger logger = LoggerFactory.getLogger(QrcodeAddController.class);
+	
+	private IQrcodeAddService qrcodeAddService = enhance(QrcodeAddServiceImpl.class);
+	
+	private IProductService productService = enhance(ProductServiceImpl.class);
+	
+	/**
+	 * 进入产码页面
+	 */
+//	@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+	public void qrcode(){
+		AdminView loginUser = getLoginUser();
+		List<String> urlList = qrcodeAddService.getPropertiesUrl();
+		setAttr("urlList", urlList);
+		List<Record> productList = productService.getProductInfoList(loginUser);
+		setAttr("productList", productList);
+		render("/page/qrcode.jsp");
+	}
+	
+	/**
+	 * 产码
+	 */
+//	@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+	public void qrCodeAdd(){
+		AdminView loginUser = getLoginUser();
+		String url = getPara("url");
+		String code = getPara("code");
+		Integer number = getParaToInt("number");
+		Integer addNum = getParaToInt("addNum");
+		String id = getPara("id");
+		Integer type = getParaToInt("type");
+		String area = getPara("area");
+		AdminView loginUser2 = getLoginUser();
+		String filePath = getSession().getServletContext().getRealPath("/") +  "QRCode";
+		String zipFilePath = qrcodeAddService.getZipFilePath(url,code, number, filePath,addNum,id,type,area,loginUser2);		
+		renderText(zipFilePath);
+	}
+	
+	/**
+	 * 获取产码数量
+	 */
+	public void getProgress(){
+		String id = getPara("id");
+		Integer progress = qrcodeAddService.getProgress(id);		
+		renderText(progress+"");
+	}
+}

+ 94 - 0
src/main/java/com/qlm/controller/core/RecordController.java

@@ -0,0 +1,94 @@
+package com.qlm.controller.core;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.service.IRecordService;
+import com.qlm.service.impl.RecordServiceImpl;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMessage;
+import com.qlm.view.core.AdminView;
+
+@RequestUrl("/record")
+public class RecordController extends CommonController {
+	private static final Logger logger = LoggerFactory.getLogger(RecordController.class);
+	private  IRecordService recordService = enhance(RecordServiceImpl.class);	
+	
+	/**
+	 * 进入产码记录页面
+	 */
+	public void getRecordList(){	
+		int uid = getLoginUser().getId();
+		List<Record> t_area = Db.find("select * from t_area where uid = ?",uid);
+		setAttr("areas", JsonKit.toJson(t_area));
+		renderJsp("/page/recordList.jsp");
+	}
+	
+	/**
+	 * 产码记录列表分页
+	 */
+	public void recordListFound() {
+		AdminView loginUser = getLoginUser();
+		// 接收参数
+		String aoData = getPara("aoData");
+		
+		//logger.info("recordListFound param:aoData(" + aoData + ")");
+		// 分页查询
+		String jsonStr = recordService.getRecordList(aoData,loginUser);
+		//logger.info("recordListFound return:jsonStr(" + jsonStr + ")");
+		renderJson(jsonStr);
+	}
+	
+	/**
+	 * 二维码启用/禁用
+	 */
+	public void setValid(){
+		Integer id = getParaToInt("id");
+		Integer valid = getParaToInt("valid");
+		Integer config_id = getParaToInt("config_id");
+		logger.info("setValid param:id(" + id + ")");
+		logger.info("setValid param:valid(" + valid + ")");
+		logger.info("setValid param:config_id(" + config_id + ")");
+		ResultMessage rm = recordService.setValid(id, valid,config_id);
+		logger.info("setValid return:rm(" + rm + ")");
+		renderJson(rm);
+	}
+	
+	public void updateArea(){
+		Integer id = getParaToInt("id");
+		Integer config_id = getParaToInt("config_id");
+		logger.info("setValid param:id(" + id + ")");
+		logger.info("setValid param:config_id(" + config_id + ")");
+		ResultMessage rm = recordService.updateArea(id, config_id);
+		logger.info("setValid return:rm(" + rm + ")");
+		renderJson(rm);
+	}
+	
+	public void jihuo(){
+		String id = getPara("id");
+		String area = getPara("product");
+		Record codeRecord = Db.findById("t_record", id);
+		Integer type = WxUtil.getInt("type_", codeRecord);
+		int uid = getLoginUser().getId();
+		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
+		String masterCodeStr = sf.format(new Date());
+		Record masterCode = new Record();
+		masterCode.set("master_code", masterCodeStr)
+		.set("create_time", new Date()).set("send_time", new Date())
+		.set("area_id", area).set("type_", type);
+		Db.save("t_master", masterCode);
+		Db.update("update t_qcode_a set master_code = ?,area_id = ? where record_id = ? ",masterCodeStr,area,id);
+		Record data = new Record();
+		data.set("status", true);
+		renderJson(data);
+	}
+}

+ 173 - 0
src/main/java/com/qlm/controller/core/SearchController.java

@@ -0,0 +1,173 @@
+package com.qlm.controller.core;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+import com.alibaba.fastjson.JSON;
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.entity.ScanRecord;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.poi.ExcelHeader;
+import com.qlm.poi.ExcelUtil;
+import com.qlm.tongji.service.ISearchService;
+import com.qlm.tongji.service.impl.SearchServiceImpl;
+import com.qlm.tools.DateUtils;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+@RequestUrl("/search")
+public class SearchController extends CommonController {
+	
+	private ISearchService searchService = enhance(SearchServiceImpl.class);
+	
+	public void getSearch(){
+		renderJsp("/page/search.jsp");
+	}
+	
+	/**
+	 * 查询扫码记录
+	 */
+	public void searchByQrcode(){
+		String id = getPara("num_");
+		AdminView loginUser = getLoginUser();
+		ResultMsg rm = searchService.searchByQrcode(id,loginUser);
+		renderJson(rm);
+	}
+	
+	public void searchUser(){
+	    renderJsp("/page/searchUser.jsp");
+	}
+	
+	public void su(){
+	    Integer type = getParaToInt("type",0);
+	    String startTime = null;
+	    String endTime = null;
+	    if(type == 0){
+	        startTime = DateUtils.getTodayStart();
+            endTime = DateUtils.getTodayEnd();
+	    }else{
+	        startTime = DateUtils.getWeekStart();
+	        endTime = DateUtils.getTodayEnd();
+	    }
+	    ResultMsg rm = searchService.searchOneDay(startTime,endTime);
+	    renderJson(rm);
+	}
+	
+	public void getUser(){
+		renderJsp("/page/userSearch.jsp");
+	}
+	
+	public void getFind(){
+		
+		int uid = getLoginUser().getId();
+		String scanTime = DateUtils.dateToString(DateUtils.PATTEN_YMD)+" 00:00:00";
+		String today = DateUtils.dateToString(DateUtils.PATTEN_YMD);
+		List<ScanRecord> list =new ArrayList<ScanRecord>();
+		setAttr("today", today);
+		setAttr("scanRecordList", list);
+		List<Record> ywyList = Db.find("select * from t_ywy");
+		List<Record> retaiList = Db.find("select * from t_retail");
+		Map<Integer, Record> ywyMap = WxUtil.toMapInt(ywyList, "id");
+		Map<Integer, Record> retailMap = WxUtil.toMapInt(retaiList, "id");
+		setAttr("ywyMap", JsonKit.toJson(ywyMap));
+		setAttr("retailMap", JsonKit.toJson(retailMap));
+		List<Record> shiWu = Db.find("select * from t_prize_shiwu where uid = ?",uid);
+		Map<Integer, Record> mapInt = WxUtil.toMapInt(shiWu, "id");
+		setAttr("shiwuMap", JsonKit.toJson(mapInt));
+		
+		List<Record> quyuList = Db.find("select * from t_area where uid = ?",uid);
+		setAttr("quyu", quyuList);
+		
+		setAttr("ywyList", ywyList);
+		setAttr("retaiList", retaiList);
+		setAttr("shiWu", shiWu);
+		
+		renderJsp("/page/scanSearch.jsp");
+	}
+	
+	/**
+	 * 依据时间查询扫码情况
+	 */
+	public void searchByDate(){
+		AdminView loginUser = getLoginUser();
+		String scanTime = getPara("scanTime")!=null?(getPara("scanTime")+" 00:00:00"):null;
+		String endTime = getPara("endTime")!=null?(getPara("endTime")+" 23:59:59"):null;
+		String area = getPara("area");
+		String ywy = getPara("ywy");
+		String retail = getPara("retail");
+		String prize = getPara("prize");
+		ResultMsg rm = searchService.searchByDate2(scanTime,endTime,ywy,retail,prize,area,loginUser);
+		renderJson(rm);
+	}
+	
+	public void exportByDate(){
+		AdminView loginUser = getLoginUser();
+		String date = getPara("scanTime");
+		String endTime = getPara("endTime")!=null?(getPara("endTime")+" 23:59:59"):null;
+		String scanTime = date!=null?(date+" 00:00:00"):null;
+		String area = getPara("area");
+		String ywy = getPara("ywy");
+		String retail = getPara("retail");
+		String prize = getPara("prize");
+		List<Record>list = searchService.exportByDate(scanTime,endTime,ywy,retail,prize,area,loginUser);
+		String keys[] = {"qrcode_id","openid","scan_time","address","area","prize_name","desc_","number","nick_name","pici","weixin_no_"};
+		String names[] = {"二维码ID","openid","扫码时间","扫码地址","发货区域","奖项","品项","编号","昵称","批次","微信单号"};
+		
+		ExcelHeader[] headers = new ExcelHeader[keys.length];
+		for (int i = 0; i < keys.length; i++) {
+			ExcelHeader header = new ExcelHeader(names[i], keys[i]);
+			headers[i] = header;
+		}
+		String orderNo = WxUtil.getOrderNo();
+		File exportNormal = ExcelUtil.exportNormal(date+"扫码记录_"+orderNo,date, headers, list);
+		renderFile(exportNormal);
+	}
+	
+	public void searchByNickname(){
+		String nickname = getPara("nickname");
+		Integer type_ = getParaToInt("type_")==null?1:getParaToInt("type_");
+		AdminView loginUser = getLoginUser();
+		ResultMsg rm = searchService.searchByNickname(nickname,type_,loginUser);		
+		renderJson(rm);
+	}
+	
+	public void findScanInfoByOpenid(){
+		String openid = getPara("openid");
+		ResultMsg rm = searchService.findScanInfoByOpenid(openid);
+		System.out.println(rm);
+		renderJson(rm);
+	}
+
+	public void upload(){
+		render("/page/upload.jsp");
+	}
+
+	public void uploads(){
+		String utime = getPara("startTime");
+		String start = utime + " 00:00:00";
+		String end = utime + " 23:59:59";
+		Map<String,Object> rs = new HashMap<>();
+		BigDecimal masterCount = Db.queryBigDecimal("select sum(master_count) from t_uploadrecord where create_time >= ? and create_time <=?",start,end);
+		BigDecimal childCount = Db.queryBigDecimal("select sum(child_count) from t_uploadrecord where create_time >= ? and create_time <=?",start,end);
+		BigDecimal successCount = Db.queryBigDecimal("select sum(success_count) from t_uploadrecord where create_time >= ? and create_time <=?",start,end);
+
+		List<Record> ulist = Db.find("select id,file_name,master_count,child_count,create_time,success_count from t_uploadrecord where create_time >= ? and create_time <=?",start,end);
+		rs.put("mc", Objects.toString(masterCount));
+		rs.put("cc",Objects.toString(childCount));
+		rs.put("sc",Objects.toString(successCount));
+		rs.put("ulist",ulist);
+		renderJson(rs);
+	}
+	
+}

+ 20 - 0
src/main/java/com/qlm/controller/core/ShiwuController.java

@@ -0,0 +1,20 @@
+package com.qlm.controller.core;
+
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.controller.common.CommonUserController;
+@RequestUrl("/shiwu")
+public class ShiwuController extends CommonUserController{
+
+	@Override
+	protected String getTableName(String key) {
+		// TODO Auto-generated method stub
+		return "t_prize_shiwu";
+	}
+
+	@Override
+	protected String getPath(String key) {
+		// TODO Auto-generated method stub
+		return "/page/t_prize_shiwu/index.jsp";
+	}
+}

+ 157 - 0
src/main/java/com/qlm/controller/core/StatisticController.java

@@ -0,0 +1,157 @@
+package com.qlm.controller.core;
+
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.alibaba.fastjson.JSON;
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IProductService;
+import com.qlm.service.ISearchService;
+import com.qlm.service.impl.ProductServiceImpl;
+import com.qlm.service.impl.SearchServiceImpl;
+import com.qlm.tongji.service.IStatisticService;
+import com.qlm.tongji.service.impl.StatisticServiceImpl;
+import com.qlm.tools.DateUtils;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.tools.StringUtils;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.EchartDataView;
+import com.qlm.view.core.AdminView;
+@RequestUrl("/statistics")
+public class StatisticController extends CommonController {
+
+	protected final static Logger logger = LoggerFactory
+			.getLogger(StatisticController.class);
+
+	private IStatisticService statisticService = enhance(StatisticServiceImpl.class);
+	
+	private ISearchService searchService = enhance(SearchServiceImpl.class);
+	
+	private IProductService productService = enhance(ProductServiceImpl.class);
+
+	public void scanRecordChart() {
+		List<Record> areaList = searchService.getAreaCodeByRecord(getLoginUser());
+		setAttr("areaList", areaList);
+		logger.info("method:StatisticController-scanRecordChart");
+		// List<String> areaList = adminService.getAreaList();
+		// setAttr("areaList", areaList);
+		List<Record> productList = productService.getProductInfoList(getLoginUser());
+		String[] titleStrs = new String[productList.size()];
+		
+		Integer [] ids = new Integer[productList.size()];
+		int i = 0;
+		for(Record record : productList){
+			titleStrs[i] = JFinalUtil.getStr("desc_", record)+"扫码数量";
+			ids[i] = WxUtil.getInt("type_", record);
+			i++;
+		}
+		setAttr("titleStrs", JSON.toJSON(titleStrs));
+		setAttr("ids", JSON.toJSON(ids));
+		render("/page/tongji/scanRecordChart.jsp");
+	}
+
+	public void dayScanRecordChart() {
+		List<Record> areaList = searchService.getAreaCodeByRecord(getLoginUser());
+		setAttr("areaList", areaList);
+		List<Record> productList = productService.getProductInfoList(getLoginUser());
+		String[] titleStrs = new String[productList.size()];
+		int i = 0;
+		for(Record record : productList){
+			titleStrs[i] = JFinalUtil.getStr("desc_", record)+"扫码数量";
+			i++;
+		}
+		setAttr("titleStrs", JSON.toJSON(titleStrs));
+		logger.info("method:StatisticController-dayScanRecordChart");
+		render("/page/tongji/dayScanRecordChart.jsp");
+	}
+
+	public void getSRECharts() {
+		logger.info("method:StatisticController-getSRECharts");
+		AdminView loginUser = getLoginUser();
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String area = getPara("area");
+		
+		if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
+			endDate=DateUtils.dateToString(DateUtils.PATTEN_YMD);
+			startDate=DateUtils.dateToString(DateUtils.addDay(new Date(), -7),DateUtils.PATTEN_YMD);
+		}
+
+		EchartDataView dev = statisticService.getScanEDV(startDate, endDate,area,loginUser);
+		renderJson(dev);
+	}
+	
+	public void getDSRECharts() {
+		String area = getPara("area");
+		logger.info("method:StatisticController-getDSRECharts");
+		EchartDataView dev = statisticService.getScanEDVOneDay(area,getLoginUser());
+		renderJson(dev);
+	}
+	
+	public void hbRecordChart() {
+		List<Record> areaList = searchService.getAreaCodeByRecord(getLoginUser());
+		setAttr("areaList", areaList);
+		logger.info("method:StatisticController-scanRecordChart");
+		// List<String> areaList = adminService.getAreaList();
+		// setAttr("areaList", areaList);
+		List<Record> productList = productService.getProductInfoList(getLoginUser());
+		String[] titleStrs = new String[productList.size()];
+		int i = 0;
+		for(Record record : productList){
+			titleStrs[i] = JFinalUtil.getStr("desc_", record)+"红包数量";
+			i++;
+		}
+		setAttr("titleStrs", JSON.toJSON(titleStrs));
+		render("/page/tongji/hbRecordChart.jsp");
+	}
+
+	public void dayHbRecordChart() {
+		List<Record> areaList = searchService.getAreaCodeByRecord(getLoginUser());
+		setAttr("areaList", areaList);
+		logger.info("method:StatisticController-dayScanRecordChart");
+		List<Record> productList = productService.getProductInfoList(getLoginUser());
+		String[] titleStrs = new String[productList.size()];
+		int i = 0;
+		for(Record record : productList){
+			titleStrs[i] = JFinalUtil.getStr("desc_", record)+"红包数量";
+			i++;
+		}
+		setAttr("titleStrs", JSON.toJSON(titleStrs));
+		render("/page/tongji/dayHbRecordChart.jsp");
+	}
+
+	public void getHbSRECharts() {
+		logger.info("method:StatisticController-getSRECharts");
+
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String area = getPara("area");
+		
+		if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
+			endDate=DateUtils.dateToString(DateUtils.PATTEN_YMD);
+			startDate=DateUtils.dateToString(DateUtils.addDay(new Date(), -7),DateUtils.PATTEN_YMD);
+		}
+
+		EchartDataView dev = statisticService.getHbEDV(startDate, endDate,area,getLoginUser());
+		renderJson(dev);
+	}
+	
+	public void getHbDSRECharts() {
+		String area = getPara("area");
+		logger.info("method:StatisticController-getDSRECharts");
+		EchartDataView dev = statisticService.getHbEDVOneDay(area,getLoginUser());
+		renderJson(dev);
+	}
+	
+	
+	
+	
+}

+ 178 - 0
src/main/java/com/qlm/controller/core/TjSearchController.java

@@ -0,0 +1,178 @@
+package com.qlm.controller.core;
+
+import java.time.LocalDateTime;
+import java.util.Date;
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IProductService;
+import com.qlm.service.ISearchService;
+import com.qlm.service.impl.ProductServiceImpl;
+import com.qlm.service.impl.SearchServiceImpl;
+import com.qlm.tools.DateUtils;
+import com.qlm.tools.LocalDateUtils;
+import com.qlm.tools.StringUtils;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+
+@RequestUrl("/tjsearch")
+public class TjSearchController extends CommonController {
+	
+	private ISearchService searchService = enhance(SearchServiceImpl.class);
+	
+	private IProductService productService = enhance(ProductServiceImpl.class);
+	
+	public void getSearch(){
+		renderJsp("/page/search.jsp");
+	}
+	
+	/**
+	 * 查询扫码记录
+	 */
+	public void searchByQrcode(){
+		String id = getPara("id");
+		ResultMsg rm = searchService.searchByQrcode(id);
+		renderJson(rm);
+	}
+	
+	public void getFind(){
+		String currentDate = LocalDateUtils.localToDateStr(LocalDateTime.now().minusDays(1));
+		List<Record> areaList = searchService.getAreaCodeByRecord(getLoginUser());
+		setAttr("today", currentDate);
+		setAttr("areaList", areaList);
+		List<Record> productList = productService.getProductInfoList(getLoginUser());
+		setAttr("productList", productList);
+		renderJsp("/page/find.jsp");
+	}
+	
+	/**
+	 * 依据时间和金额查询发放红包数量
+	 */
+	public void searchByDateAndMoney(){
+		String date = getPara("date");
+		String end_time = getPara("end_time");
+		String type_ = getPara("type_");
+		String area_code = getPara("area_code");
+		ResultMsg rm = searchService.searchByDateAndMoney(date,end_time, type_,area_code);
+		renderJson(rm);
+	}	
+	
+	public void getUserFind(){
+		renderJsp("/page/userList.jsp");
+	}
+	
+	public void searchByCountAndMoney(){
+		Integer counts = getParaToInt("counts");
+		Integer dayCounts = getParaToInt("dayCounts");
+		Integer money = getParaToInt("money")!= null?getParaToInt("money") *100:null;
+		String date = getPara("date");
+		String aoData = getPara("aoData");
+		AdminView loginUser = getLoginUser();
+		String json = searchService.searchByCountAndMoney(counts, dayCounts, money,date,aoData,loginUser);
+		renderJson(json);
+	}
+	
+	public void getAreaHbFind(){
+		String currentDate = DateUtils.getCurrentDateString();
+		setAttr("today", currentDate);
+		List<Record> productList = productService.getProductInfoList(getLoginUser());
+		setAttr("productList", productList);
+		renderJsp("/page/areafind.jsp");
+	}
+	
+	public void getAreaHbFindList(){
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String type_ = getPara("type_");
+		
+		if(StringUtils.isEmpty(startDate) || StringUtils.isEmpty(endDate)){
+			endDate=DateUtils.dateToString(DateUtils.PATTEN_YMD);
+			startDate=DateUtils.dateToString(DateUtils.addDay(new Date(), -7),DateUtils.PATTEN_YMD);
+		}
+		ResultMsg rm = searchService.searchAreaHbBySendTimeAndType(startDate, endDate,type_);
+		renderJson(rm);
+	}
+
+	public void total(){
+		List<Record> pros = Db.find("select * from t_product");
+		setAttr("types",pros);
+		List<Record> areas = Db.find("select * from t_qcode_hb_config");
+		setAttr("areas",areas);
+		renderJsp("/page/total.jsp");
+	}
+
+    public void realTotal(){
+        List<Record> pros = Db.find("select * from t_product");
+        setAttr("types",pros);
+        List<Record> areas = Db.find("select * from t_qcode_hb_config");
+        setAttr("areas",areas);
+        renderJsp("/page/realTotal.jsp");
+    }
+
+
+	public void realFind(){
+        List<Record> areaList = searchService.getAreaCodeByRecord(getLoginUser());
+        setAttr("areaList", areaList);
+        List<Record> productList = productService.getProductInfoList(getLoginUser());
+        setAttr("productList", productList);
+        renderJsp("/page/realFind.jsp");
+    }
+
+    public void searchByCurrentAndMoney(){
+        String type_ = getPara("type_");
+        String area_code = getPara("area_code");
+        if(StrKit.isBlank(type_) || StrKit.isBlank(area_code)){
+            return;
+        }
+        ResultMsg rm = searchService.searchByCurrentAndMoney(type_,area_code);
+        renderJson(rm);
+    }
+
+	public void grandTotal(){
+		String[] type = getParaValues("type[]");
+		if(type == null || type.length<1){
+		    return;
+        }
+		String startTime = getPara("startTime");
+		String endTime = getPara("endTime");
+		Integer group = getParaToInt("group");
+		renderJson(searchService.totla(type,startTime,endTime,group));
+	}
+
+	public void grandRealTotal(){
+        String[] type = getParaValues("type[]");
+        renderJson(searchService.totla(type));
+    }
+	
+	public void hbTj(){
+		AdminView loginUser = getLoginUser();
+		int uid = loginUser.getId();
+		List<Record> find = Db.find("select * from t_product where uid = ?",uid);
+		setAttr("products", find);
+		render("/page/hbSearch.jsp");
+	}
+	
+	public void gethbTj(){
+		AdminView loginUser = getLoginUser();
+		int uid = loginUser.getId();
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String type = getPara("type");
+		List<Record> find  = null;
+		if(!WxUtil.isNull(type)){
+			 find = Db.find("select amount,count(*) c from t_scanrecord where uid="+uid+" and send_time>='"+startDate+" 00:00:00' and send_time<='"+endDate+" 23:59:59' and type_ = ?  group by amount",type);
+		}else{
+			 find = Db.find("select amount,count(*) c from t_scanrecord where uid="+uid+" and send_time>='"+startDate+" 00:00:00' and send_time<='"+endDate+" 23:59:59'  group by amount");
+		}
+		renderJson(find);
+	}
+	
+}

+ 232 - 0
src/main/java/com/qlm/controller/core/TypeController.java

@@ -0,0 +1,232 @@
+package com.qlm.controller.core;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.kit.HttpKit;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.service.TypeServices;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 
+ * @author lds
+ * @date 2019/11/01
+ */
+@RequestUrl("/p")
+public class TypeController extends CommonController {
+    
+    public void index(){
+        render("/page/type.jsp");
+    }
+    
+    public void types(){
+    	AdminView loginUser = getLoginUser();
+        renderJson(TypeServices.getTypes(loginUser));
+    }
+    
+    public void addType(){
+        Record r = new Record();
+        Record product = new Record();
+        product.set("type_", TypeServices.typeId()+1).set("name_", getPara("name_")).set("desc_", getPara("desc_")).set("isUpload_", 0);
+        Record pro = TypeServices.addType(product,getLoginUser());
+        setAttr("record",null);
+        if(pro == null){
+            r.set("status", false);
+            r.set("msg", "添加品类失败");
+        }else{
+            r.set("status", true);
+            r.set("msg", "操作成功");
+            r.set("product", pro);
+        }
+        renderJson(r);
+    }
+    
+    public void sycnProduct(){
+    	getProduct();
+		renderText("ok");
+	}
+	
+	private  void getProduct(){
+		Map<String,String> headers = new HashMap<String,String>();
+		headers.put("source", "tianmu");
+		headers.put("token", "0fc6b6c3b03da9c6f83e515942163519");
+		String post = HttpKit.get("https://wyywy.hunanwangyou.com/external/product/list", null, headers);
+		JSONObject parseObject = JSONObject.parseObject(post);
+		JSONArray jsonArray = parseObject.getJSONArray("data");
+		for (int i = 0; i < jsonArray.size(); i++) {
+			JSONObject jsonObject = jsonArray.getJSONObject(i);
+			Integer id = jsonObject.getInteger("id");
+			String name = jsonObject.getString("name");
+			Integer categaryId = jsonObject.getInteger("categoryId");
+			if(categaryId == 2){
+				continue;
+			}
+			Record area = Db.findById("t_product","product_id", id);
+			if(area != null){
+				Db.update("update t_product set name_ = ? where product_id =?",name,id);
+			}else{
+				Record info = new Record();
+				info.set("product_id", id).set("name_", name).set("type_", id)
+				.set("desc_", name);
+				Db.save("t_product", info);
+			}
+		}
+	}
+    
+    public void type(){
+        Integer id = getParaToInt("id",0);
+        renderJson(TypeServices.getTypeById(id));
+    }
+    
+    public void update(){
+        Record r = new Record();
+        Record product = TypeServices.getTypeById(getParaToInt("id"));
+        if(product != null){
+            product.set("name_", getPara("name_")).set("desc_", getPara("desc_"));
+            Record pro = TypeServices.updateType(product);
+            if(pro != null){
+                r.set("status", true);
+                r.set("msg", "操作成功");
+                r.set("product", pro);
+            }else{
+                r.set("status", false);
+                r.set("msg", "更新品类失败");
+            }
+        }else{
+            r.set("status", false);
+            r.set("msg", "指定的品类不存在");
+        }
+        renderJson(r);
+    }
+    
+    public void delete(){
+        Integer id =  getParaToInt("id",0);
+        Record r = new Record();
+        if(TypeServices.deleteType(id)){
+            r.set("status", true);
+            r.set("msg", "操作成功");
+        }else{
+            r.set("status", false);
+            r.set("msg", "删除品类失败");
+        }
+        renderJson(r);
+    }
+    
+    
+    public void ruleList(){
+		List<Record> find = Db.find("select * from t_product");
+		setAttr("products", find);
+		Map<Integer, Record> groupByStr = WxUtil.toMapInt(find, "type_");
+		setAttr("productMaps", JsonKit.toJson(groupByStr));
+		List<Record> areasList = Db.find("select * from t_area");
+		setAttr("areas", areasList);
+		Map<Integer, Record> areamspSt = WxUtil.toMapInt(areasList, "id");
+		setAttr("areaMaps", JsonKit.toJson(areamspSt));
+		
+    	 render("/page/rule/list.jsp");    	
+    }
+    
+    
+    
+    public void ruleListQuery(){
+    	List<Record> find = Db.find("select * from t_rule order by id desc");
+    	Map<Integer, Record> mapInt = WxUtil.toMapInt(find, "id");
+    	List<Record> find2 = Db.find("select * from t_rule_product");
+    	Map<Integer,StringBuilder> mas = new HashMap<Integer, StringBuilder>();
+    	Map<Integer,StringBuilder> areas = new HashMap<Integer, StringBuilder>();
+    	for (Record record : find2) {
+    		Integer ruleId = WxUtil.getInt("rule_id", record);
+    		String product_type = record.getStr("product_type");
+    		int areaId = WxUtil.getInt("area_id", record);
+    		
+    		StringBuilder stringBuilder2 = areas.get(ruleId);
+    		if(stringBuilder2 == null){
+    			stringBuilder2 = new StringBuilder();
+    		}
+    		if(stringBuilder2.length()>0){
+    			stringBuilder2.append(",");
+    		}
+    		stringBuilder2.append(areaId);
+    		areas.put(ruleId, stringBuilder2);
+    		
+			StringBuilder stringBuilder = mas.get(ruleId);
+			if(stringBuilder == null){
+				stringBuilder = new StringBuilder();
+			}
+			if(stringBuilder.length()>0){
+				stringBuilder.append(",");
+			}
+			stringBuilder.append(product_type);
+			mas.put(ruleId, stringBuilder);
+		}
+    	Set<Integer> keySet = mas.keySet();
+    	
+    	for (Integer ruleId : keySet) {
+    		StringBuilder stringBuilder = mas.get(ruleId);
+    		Record rule = mapInt.get(ruleId);
+    		StringBuilder stringBuilder2 = areas.get(ruleId);
+    		if(rule!=null){
+    			rule.set("products", stringBuilder.toString());
+    			rule.set("areas", stringBuilder2.toString());
+    		}
+    	}
+    	renderJson(find);
+    }
+    
+    public void saveRule(){
+	    Record r = new Record();
+    	int id = getParaToInt("id",-1);
+    	String name = getPara("name");
+    	String types = getPara("products");
+    	String detail = getPara("detail");
+    	String areas = getPara("areas");
+    	if(id == -1){
+    		Record rule = new Record();
+    		rule.set("rule_name", name)
+    		.set("detail_", detail).set("create_time", new Date());
+    		Db.save("t_rule", rule);
+    		id = WxUtil.getInt("id", rule);
+    	}else{
+    		Record rule = Db.findById("t_rule", id);
+    		rule.set("rule_name", name)
+    		.set("detail_", detail);
+    		Db.update("t_rule", rule);
+    		Db.update("delete from t_rule_product where rule_id = ?",id);
+    	}
+    	String[] split = types.split(",");
+    	String[] split2 = areas.split(",");
+    	for (String area : split2) {
+    		for (String string : split) {
+    			Record info  =new Record();
+    			info.set("rule_id", id).set("product_type", string).set("area_id", area);
+    			Db.save("t_rule_product", info);
+    		}
+		}
+    	
+    	r.set("status", true);
+    	  renderJson(r);
+    }
+    public void deleteRule(){
+        Integer id =  getParaToInt("id",0);
+        Record r = new Record();
+        Db.deleteById("t_rule", id);
+        Db.update("delete from t_rule_product where rule_id = ?",id);
+        r.set("status", true);
+        r.set("msg", "操作成功");
+        renderJson(r);
+    }
+    public void ruleDetail(){
+    	
+    }
+}

+ 39 - 0
src/main/java/com/qlm/controller/core/UnPayInfoController.java

@@ -0,0 +1,39 @@
+package com.qlm.controller.core;
+
+
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonUserController;
+import com.qlm.entity.ScanRecord;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IUnPayInfoService;
+import com.qlm.service.impl.UnPayInfoService;
+import com.qlm.view.UnPayView;
+import com.qlm.view.core.AdminView;
+
+@RequestUrl("/unpay")
+public class UnPayInfoController extends CommonUserController {
+	
+	private IUnPayInfoService UnPayInfoService = enhance(UnPayInfoService.class);
+	
+	/**
+	 * 获取未发红包列表
+	 */
+	public void getUnPayPage(){
+		AdminView loginUser = getLoginUser();
+		List<UnPayView> list = UnPayInfoService.getUnPayInfo(loginUser);
+		setAttr("unPayList", list);
+		render("/page/unPayInfoList.jsp");
+	}
+	
+//	public void getUnPayInfo(){
+//		// 接收参数
+////		String jsonStr = UnPayInfoService.getUnPayInfo();
+//		System.out.println(jsonStr);
+//		renderJson(jsonStr);
+//	}
+	
+}

+ 181 - 0
src/main/java/com/qlm/controller/editor/ConsumerController.java

@@ -0,0 +1,181 @@
+package com.qlm.controller.editor;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import com.jfinal.aop.Clear;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.upload.UploadFile;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.controller.editor.service.EditorService;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+
+
+@RequestUrl("/editor")
+public class ConsumerController extends CommonController{
+	
+	
+	
+	public void index(){
+		int total =0;
+		int exchangeTotal =0;
+		int totalGameCard = 0;
+		setAttr("totalUser", total);
+		setAttr("exchangeTotal", exchangeTotal);
+		setAttr("totalGameCard", totalGameCard);
+		render("/pages/index_v1.jsp");
+	}
+	
+	public void listSysTemplate(){
+		int type = getParaToInt("type",1);
+		List<Record> find = Db.find("select * from t_template_type");
+		setAttr("types", find);
+		setAttr("type", type);
+		List<Record> listTemplates = EditorService.listSysTemplate(type);
+		setAttr("list", listTemplates);
+		render("/editors/template_list.jsp");
+	}
+	
+	public void userTemplateList(){
+		int id = getLoginUser().getId();
+		int type = getParaToInt("type",1);
+		List<Record> find = Db.find("select * from t_template_type");
+		setAttr("types", find);
+		setAttr("type", type);
+		setAttr("userId", id);
+		List<Record> listTemplates = EditorService.listTemplates(id,type);
+		setAttr("list", listTemplates);
+		render("/editors/user_template_list.jsp");
+	}
+	
+	public void saveTemplate(){
+		String html = getPara("html");
+		String name = getPara("name");
+		String id = getPara("id");
+		int type = getParaToInt("type",0);
+		AdminView user = getLoginUser();
+		Record record = EditorService.saveTemplate(id,user,html, name,type);
+		Integer t_id = WxUtil.getInt("t_id", record);
+		setSessionAttr("editting_id", t_id+"");
+		renderJson(record);
+	}
+	
+	public void delTemplate(){
+		String id = getPara(0);
+		Record record = EditorService.delTemplate(id,getLoginUser());
+		renderJson(record);
+	}
+	
+	public void editor(){
+		String id  = getSessionAttr("editting_id");
+		if(id != null){
+			removeSessionAttr("editting_id");
+			redirect("/editor/editor/"+id);
+			return;
+		}else{
+			id =getPara(0,"");
+			if(WxUtil.isNull(id)){
+				id = getPara("s_id","");
+				
+			}
+		}
+		Record record = EditorService.getTemplate(id);
+		if(record == null){
+			record = new Record();
+			record.set("content_", "");
+			record.set("name_", "新页面");
+			int type = getParaToInt("type",0);
+			record.set("page_type", type);
+		}
+		AdminView loginUser = getLoginUser();
+		int type_ = WxUtil.getInt("type_", record);
+		int level = loginUser.getLevel();
+		if(level == 1 ){//管理员
+//			record.set("id", null);
+		}else{
+			if(type_ == 1){//系统模板
+				record.set("id", null);
+			}else{
+				int user_id = WxUtil.getInt("user_id", record);
+				if(getLoginUser().getId() != user_id){
+					record.set("id", null);
+					record.set("content_", "");
+					record.set("name_", "新页面");
+				}
+			}
+		}
+		
+		HttpServletResponse response = getResponse();
+		response.setHeader("Cache-Control", "no-store");  
+		response.setDateHeader("Expires", 0);  
+		setAttr("record", record);
+		render("/editors/editor.jsp");
+	}
+	
+	public void acivityPrizeInfo(){
+			String id = getPara("id");
+			setAttr("id", id);
+			render("/pages/consumer/activity_prize_info.jsp");
+	}
+	
+	
+	public void prizeDetail(){
+		String date_ = getPara("date");
+		String id = getPara("id");
+		setAttr("id", id);
+		setAttr("date", date_);
+		render("/pages/consumer/activity_prize_detail.jsp");
+	}
+	
+	
+	
+	@Clear
+	public void uploadImg(){
+		UploadFile uploadFile = getFile();
+		Record r = EditorService.saveFile(uploadFile);
+		renderJson(r);
+	}
+	
+	
+	@Clear
+	public void preview(){
+		String t_id = getPara(0);
+		AdminView user = getLoginUser();
+		Record record = EditorService.getTemplate(t_id);
+		setAttr("record", record);
+		setAttr("id",t_id);
+		render("/pages/editor/preview.jsp");
+	}
+	
+	
+	@Clear
+	public void previewByPhone(){
+		String id = getPara(0);
+		Record record = EditorService.getTemplate(id);
+		setAttr("record", record);
+		render("/pages/editor/previewByPhone.jsp");
+	}
+
+	
+	public void pwd(){
+		render("/pages/change_pwd.jsp");
+	}
+	
+//	public void changePwd(){
+//		Record r = new Record();
+//		String pwd = getPara("pwd","");
+//		if(!WxUtil.isNull(pwd)){
+//			getLoginUser().set("password", pwd).update();
+//			r.set("status", true);
+//		}else{
+//			r.set("status", false);
+//		}
+//		renderJson(r);
+//	}
+//	
+	
+}

+ 127 - 0
src/main/java/com/qlm/controller/editor/service/EditorService.java

@@ -0,0 +1,127 @@
+package com.qlm.controller.editor.service;
+
+import java.util.Date;
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.upload.UploadFile;
+import com.qlm.log.Log;
+import com.qlm.tools.QiniuUtil;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMessage;
+import com.qlm.view.core.AdminView;
+
+public class EditorService {
+	
+	public static Record getCurrentPrizeTotalMoney(String a_id){
+		Record find = Db.findFirst("select   sum(amount_*num_) total_,sum(amount_*send_num) send_total from t_activity_prize t where activity_id = ?",a_id);
+		return find;
+	}
+	
+	public static List<Record> listSysTemplate(	int pageType){
+			List<Record> find = Db.find("select * from t_template where type_ = 1  and page_type = ?",pageType);
+			return find;
+		}
+	
+	/**
+	 * 用户模板
+	 * @return
+	 */
+	public static List<Record> listTemplates(AdminView adminView,int pageType){
+		List<Record> find = Db.find("select * from t_template where type_ = 1  and page_type = ?",pageType);
+		List<Record> usersTemplate = Db.find("select * from t_template where type_ = 2 and user_id = ? and page_type = ? order by create_time desc",adminView.getId(),pageType);
+		find.addAll(usersTemplate);
+		return find;
+	}
+	
+	public static Record getActivityById(String id){
+		Record findById = Db.findById("t_activity", id);
+		return findById;
+	}
+	
+	public static List<Record> listActivityPrize(String id){
+		List<Record> find = Db.find("select  t.*,FORMAT(amount_/100,2) money_, FORMAT(amount_/100*num_,2) total_,FORMAT(amount_/100*send_num,2) send_total from t_activity_prize t where activity_id = ?",id);
+		return find;
+	}
+	
+	
+	
+	public static List<Record> listTemplates(int uid,int pageType){
+		List<Record> find2 = Db.find("select * from t_template where page_type = ? and type_ = 1",pageType);
+		String sql = "select * from t_template where user_id = ? and page_type = ?";
+		List<Record> find = Db.find(sql,uid,pageType);
+		find2.addAll(find);
+		return find2;
+	}
+
+	public static Record saveTemplate(String id, AdminView user, String html,String name_,int type) {
+		Record result = new Record();
+		int level = user.getLevel();
+		if(WxUtil.isNull(id)){
+			Integer user_id = user.getId();
+			Record template = new Record();
+			if(level == 1){//超级管理员
+				template.set("type_", 1);
+			}else{
+				template.set("user_id", user_id).set("type_", 2);
+			}
+			template.set("content_", html).set("page_type", type).set("name_", name_).set("create_time", new Date()).set("like_num", 0).set("view_num", 0);
+			
+			Db.save("t_template", template);
+			Integer template_id = WxUtil.getInt("id", template);
+			Log.info("保存模版");
+			result.set("t_id", template_id);
+			result.set("status", true);
+		}else{
+			Record template = Db.findById("t_template", id);
+			template.set("content_", html).set("name_", name_);
+			Db.update("t_template", template);
+			Integer template_id = WxUtil.getInt("id", template);
+			result.set("t_id", template_id);
+			result.set("status", true);
+		}
+		return result;
+
+	}
+
+	public static Record getTemplate(String t_id) {
+		if(WxUtil.isNull(t_id)){
+			return null;
+		}
+		Record findById = Db.findById("t_template", t_id);
+		return findById;
+	}
+
+		// TODO Auto-generated method stub
+	public static Record saveFile(UploadFile uploadFile) {
+		ResultMessage uploadImgToQiniu = QiniuUtil.uploadImgToQiniu(uploadFile);
+		Record info = new Record();
+		info.set("url", uploadImgToQiniu.getData());
+		info.set("status",uploadImgToQiniu.getState() == 0);
+		return info;
+	}
+	
+
+
+	public static Record delTemplate(String id, AdminView user) {
+		Record r = new Record();
+		int user_id = user.getId();
+		Db.deleteById("t_template", id);
+		r.set("status", true);
+		return r;
+	}
+
+	public static void cloneTemplate(Integer id) {
+		List<Record> find = Db.find("select * from t_template where type_ = 1 and page_type is null");
+		
+		for (Record record : find) {
+			record.set("type_", 2).set("user_id", id);
+			record.remove("id");
+			Db.save("t_template", record);
+		}
+		Log.info("克隆用户模板成功");
+	}
+
+
+}

+ 263 - 0
src/main/java/com/qlm/controller/hx/HexiaoController.java

@@ -0,0 +1,263 @@
+package com.qlm.controller.hx;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+@RequestUrl("/hexiao")
+public class HexiaoController extends CommonController{
+
+	
+	public void readyHexiaoList(){
+		render("/hx/list.jsp");
+	}
+	public void readyHexiaoListQuery(){
+		List<Record> shiwu = Db.find("select * from t_prize_shiwu");
+		Map<Integer,Record> map = new HashMap<Integer, Record>();
+		for (Record record : shiwu) {
+			Integer id = WxUtil.getInt("id", record);
+			map.put(id, record);
+		}
+		
+		List<Record> jxsList = Db.find("select * from t_jxs_big");
+		Map<Integer,Record> jxsMap = new HashMap<Integer, Record>();
+		for (Record record : jxsList) {
+			Integer id = WxUtil.getInt("id", record);
+			jxsMap.put(id, record);
+		}
+		List<Record> find3 = Db.find("select * from t_chang_order  where  status_ = 0 order by create_time desc");
+		for (Record bigRecord : find3) {
+			Integer jxsId = WxUtil.getInt("big_id", bigRecord);
+			String name = jxsMap.get(jxsId).getStr("name_");
+			bigRecord.set("jxsName", name);
+			String changOrderId = bigRecord.getStr("order_id");
+			List<Record> t_jxs_orders = Db.find("select * from t_jxs_order where chang_no = ?",changOrderId);
+			StringBuilder jxsOrderids = new StringBuilder();
+			for (Record jxsRecord : t_jxs_orders) {
+				String jxs_order_id = jxsRecord.getStr("order_id");
+				if(jxsOrderids.length()>0){
+					jxsOrderids.append(",");
+				}
+				jxsOrderids.append("'"+jxs_order_id+"'");
+			}
+				
+			List<Record> find = Db.find("select * from t_boss_order where jxs_order_no in ("+jxsOrderids+")");
+			StringBuilder sb = new StringBuilder();
+			for (Record record : find) {
+				String order_id = record.getStr("order_id");
+				if(sb.length()>0){
+					sb.append(",");
+				}
+				sb.append("'"+order_id+"'");
+				
+			}
+			
+			List<Record> find2 = Db.find("select shiwu_id,count(*) c from t_scanrecord where hexiao_retail_order in("+sb+") group by shiwu_id");
+			int total = 0;
+			for (Record record2 : find2) {
+				Integer shiwu_id = WxUtil.getInt("shiwu_id", record2);
+				record2.set("info", map.get(shiwu_id));
+				Integer c = WxUtil.getInt("c", record2);
+				total +=c;
+			}
+			bigRecord.set("total", total);
+			bigRecord.set("list", find2);
+		}
+		
+		
+		renderJson(find3);
+	}
+	
+	public void endOrder(){
+		Record result = new Record();
+		boolean status = false;
+		int id = getParaToInt("id");
+		String no = getPara("no");
+		int update = Db.update("update t_chang_order set status_ = 1,end_no = ?,audit_time = ? where id = ?",no,new Date(),id);
+		if(update == 1){
+			status = true;
+		}
+		result.set("status", status);
+		renderJson(result);
+	}
+	
+	public void hexiaoTongji(){
+		AdminView admin = getSessionAttr("adminView");
+		String username = admin.getUsername();
+		String jxsIdAll = "";
+		if(username.length() == 11){
+			Record findFirst = Db.findFirst("select * from t_jxs_big where tel_ = ?",username);
+			if(findFirst != null){
+				Integer big_id = WxUtil.getInt("id", findFirst);
+				jxsIdAll = big_id+"";
+			}
+		}
+		List<Record> jxsList = null;
+		if(WxUtil.isNull(jxsIdAll)){
+			 jxsList = Db.find("select * from t_jxs_big");
+		}else{
+			 jxsList = Db.find("select * from t_jxs_big where id = ?",jxsIdAll);
+		}
+		
+		setAttr("jxsList", jxsList);
+		render("/hx/tongji.jsp");
+	}
+	
+	public void hexiaoTongjiQuery(){
+		
+		
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String jxsIdAll = getPara("jxsId");
+		AdminView admin = getSessionAttr("adminView");
+		String username = admin.getUsername();
+		if(username.length() == 11){
+			Record findFirst = Db.findFirst("select * from t_jxs_big where tel_ = ?",username);
+			if(findFirst != null){
+				Integer big_id = WxUtil.getInt("id", findFirst);
+				jxsIdAll = big_id+"";
+			}
+		}
+		String sql = "";
+		if(!"all".equals(jxsIdAll)){
+			sql += " and big_id = "+jxsIdAll+" ";
+		}
+		if(!WxUtil.isNull(startDate)){
+			sql += " and create_time>= '"+startDate+" 00:00:00' ";
+		}
+		if(!WxUtil.isNull(endDate)){
+			sql += " and create_time<= '"+endDate+" 23:59:59' ";
+		}
+		List<Record> shiwu = Db.find("select * from t_prize_shiwu");
+		Map<Integer,Record> map = new HashMap<Integer, Record>();
+		for (Record record : shiwu) {
+			Integer id = WxUtil.getInt("id", record);
+			map.put(id, record);
+		}
+		
+		List<Record> jxsList = Db.find("select * from t_jxs_big");
+		Map<Integer,Record> jxsMap = new HashMap<Integer, Record>();
+		for (Record record : jxsList) {
+			Integer id = WxUtil.getInt("id", record);
+			jxsMap.put(id, record);
+		}
+		List<Record> find3 = Db.find("select * from t_chang_order  where  status_ = 1 "+sql+" order by create_time desc");
+		for (Record bigRecord : find3) {
+			Integer jxsId = WxUtil.getInt("big_id", bigRecord);
+			String name = jxsMap.get(jxsId).getStr("name_");
+			bigRecord.set("jxsName", name);
+			String big_orderId = bigRecord.getStr("order_id");
+			List<Record> t_jxs_orders = Db.find("select * from t_jxs_order where chang_no = ?",big_orderId);
+			StringBuilder jxsOrderids = new StringBuilder();
+			for (Record jxsRecord : t_jxs_orders) {
+				String jxs_order_id = jxsRecord.getStr("order_id");
+				if(jxsOrderids.length()>0){
+					jxsOrderids.append(",");
+				}
+				jxsOrderids.append("'"+jxs_order_id+"'");
+			}
+			List<Record> find = Db.find("select * from t_boss_order where jxs_order_no in ("+jxsOrderids+")");
+			StringBuilder sb = new StringBuilder();
+			for (Record record : find) {
+				String order_id = record.getStr("order_id");
+				if(sb.length()>0){
+					sb.append(",");
+				}
+				sb.append("'"+order_id+"'");
+				
+			}
+			List<Record> find2 = Db.find("select shiwu_id,count(*) c from t_scanrecord where hexiao_retail_order in("+sb+") group by shiwu_id");
+			int total = 0;
+			for (Record record2 : find2) {
+				Integer shiwu_id = WxUtil.getInt("shiwu_id", record2);
+				record2.set("info", map.get(shiwu_id));
+				Integer c = WxUtil.getInt("c", record2);
+				total +=c;
+			}
+			bigRecord.set("total", total);
+			bigRecord.set("list", find2);
+		}
+		
+		renderJson(find3);
+	}
+	
+	public void retailTongji(){
+		List<Record> jxsList = Db.find("select * from t_jxs");
+		setAttr("jxsList", jxsList);
+		render("/hx/retailHexiao.jsp");
+	}
+	
+	public void retailTongjiQuery(){
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String jxsIdAll = getPara("jxsId");
+		String status = getPara("status");
+		String sql = "";
+		if(!"all".equals(jxsIdAll)){
+			sql += " and jxs_id = "+jxsIdAll+" ";
+		}
+		if(!WxUtil.isNull(startDate)){
+			sql += " and create_time>= '"+startDate+" 00:00:00' ";
+		}
+		if(!WxUtil.isNull(endDate)){
+			sql += " and create_time<= '"+endDate+" 23:59:59' ";
+		}
+		
+		if(!"all".equals(status)){
+			sql += " and status_ = "+status;
+		}
+		List<Record> shiwu = Db.find("select * from t_prize_shiwu");
+		Map<Integer,Record> map = new HashMap<Integer, Record>();
+		for (Record record : shiwu) {
+			Integer id = WxUtil.getInt("id", record);
+			map.put(id, record);
+		}
+		
+		List<Record> ywyList = Db.find("select * from t_ywy");
+		Map<Integer,Record> retaiMap = new HashMap<Integer, Record>();
+		for (Record record : ywyList) {
+			Integer id = WxUtil.getInt("id", record);
+			retaiMap.put(id, record);
+		}
+		
+		List<Record> jxsList = Db.find("select * from t_jxs");
+		Map<Integer,Record> jxsMap = new HashMap<Integer, Record>();
+		for (Record record : jxsList) {
+			Integer id = WxUtil.getInt("id", record);
+			jxsMap.put(id, record);
+		}
+		List<Record> find3 = Db.find("select * from t_boss_order  where  create_time is not null  "+sql+" order by create_time desc");
+		for (Record jxsRecord : find3) {
+			Integer jxsId = WxUtil.getInt("jxs_id", jxsRecord);
+			String name = jxsMap.get(jxsId).getStr("name_");
+			jxsRecord.set("jxsName", name);
+			Integer ywy_id = WxUtil.getInt("ywy_id", jxsRecord);
+			
+			Record retail = retaiMap.get(ywy_id);
+			jxsRecord.set("retail", retail);
+			String order_id = jxsRecord.getStr("order_id");
+			
+			List<Record> find2 = Db.find("select shiwu_id,count(*) c from t_scanrecord where hexiao_retail_order = ? group by shiwu_id",order_id);
+			int total = 0;
+			for (Record record2 : find2) {
+				Integer shiwu_id = WxUtil.getInt("shiwu_id", record2);
+				record2.set("info", map.get(shiwu_id));
+				Integer c = WxUtil.getInt("c", record2);
+				total +=c;
+			}
+			jxsRecord.set("total", total);
+			jxsRecord.set("list", find2);
+		}
+		
+		renderJson(find3);
+	}
+	
+}

+ 92 - 0
src/main/java/com/qlm/controller/hx/JxsController.java

@@ -0,0 +1,92 @@
+package com.qlm.controller.hx;
+
+import java.util.Date;
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.controller.common.CommonUserController;
+import com.qlm.tools.WxUtil;
+@RequestUrl("/jxs")
+public class JxsController extends CommonUserController{
+ 
+ 
+ 
+ @Override
+	protected String getPath(String key) {
+		// TODO Auto-generated method stub
+		return "/page/t_jxs_big/index.jsp";
+	}
+
+
+
+	@Override
+	protected String getTableName(String key) {
+		// TODO Auto-generated method stub
+		return "t_jxs_big";
+	}
+
+
+
+@Override
+protected void beforeSave(String tableName,Record data) {
+	 data.set("status_", 1).set("create_time", new Date());
+	// TODO Auto-generated method stub
+	super.beforeSave(tableName,data);
+}
+
+
+
+@Override
+protected void afterSave(String tableName,Record record) {
+//	String tel = record.getStr("tel_");
+//	Record role = Db.findFirst("select * from t_role where role_name = '经销商'");
+//	if(role != null){
+//		Record t_admin = new Record();
+//		t_admin.set("username", tel).set("password", "e10adc3949ba59abbe56e057f20f883e")
+//		.set("role", 3).set("status", 1);
+//		Db.save("t_admin", t_admin);
+//		Integer adminId = WxUtil.getInt("id", t_admin);
+//		Record t_admin_role = new Record();
+//		int id = WxUtil.getInt("id", role,0);
+//		t_admin_role.set("userid", adminId).set("roleid", id);
+//		Db.save("t_admin_role", t_admin_role);
+//	}
+	
+	
+	
+	
+	super.afterSave(tableName,record);
+}
+
+
+
+public void changeStatus(){
+	 Record result = new Record();
+	 int id = getParaToInt("id");
+	 int status = getParaToInt("status");
+	 if(status == 1){
+		 Db.update("update t_jxs_big set status_ = 2 where id = ?",id );
+	 }else{
+		 Db.update("update t_jxs_big set status_ = 1 where id = ?",id );
+	 }
+	 result.set("status", true);
+	 renderJson(result);
+ }
+
+public void retailList(){
+	 int jxsId = getParaToInt("jxsId");
+	 setAttr("jxsId", jxsId);
+	 render("/hx/retailList.jsp");
+}
+
+public void retailListQuery(){
+	 int jxsId = getParaToInt("jxsId");
+		List<Record> find = Db.find("select * from t_retail where jxs_id = ? order by create_time desc",jxsId);
+		renderJson(find);
+		
+		
+}
+}

+ 43 - 0
src/main/java/com/qlm/controller/jinzai/ProductController.java

@@ -0,0 +1,43 @@
+package com.qlm.controller.jinzai;
+
+import java.util.List;
+
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.aop.Clear;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+
+@RequestUrl("/jinzaiProduct")
+public class ProductController extends CommonController{
+	
+
+	@Override
+	protected String getTableName(String key) {
+		// TODO Auto-generated method stub
+		return "t_jz_product";
+	}
+
+	@Override
+	protected String getPath(String key) {
+		// TODO Auto-generated method stub
+		return "/page/jinzai/t_jz_product.jsp";
+	}
+	
+	@Clear
+	public void getProduceData(){
+		JSONObject obj = new JSONObject();
+		
+		List<Record> t_jz_productList = Db.find("select * from t_jz_product");
+	
+		List<Record> t_jz_product_typeList = Db.find("select * from t_jz_product_type");
+	
+		
+		obj.put("products", t_jz_productList);
+		
+		obj.put("types", t_jz_product_typeList);
+		
+		renderJson(obj);
+	}
+}

+ 21 - 0
src/main/java/com/qlm/controller/jinzai/ProductTypeController.java

@@ -0,0 +1,21 @@
+package com.qlm.controller.jinzai;
+
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+
+@RequestUrl("/jinzaiProductType")
+public class ProductTypeController extends CommonController{
+	
+
+	@Override
+	protected String getTableName(String key) {
+		// TODO Auto-generated method stub
+		return "t_jz_product_type";
+	}
+
+	@Override
+	protected String getPath(String key) {
+		// TODO Auto-generated method stub
+		return "/page/jinzai/t_jz_product_type.jsp";
+	}
+}

+ 354 - 0
src/main/java/com/qlm/controller/pj/AreaHbConfigController.java

@@ -0,0 +1,354 @@
+package com.qlm.controller.pj;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.entity.HBRate;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.rpc.CacheNotice;
+import com.qlm.service.IAreaHbConfigService;
+import com.qlm.service.IHBRateService;
+import com.qlm.service.impl.AreaHbConfigServiceImpl;
+import com.qlm.service.impl.HBRateServiceImpl;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+
+@RequestUrl("/areaHb")
+public class AreaHbConfigController extends CommonController {
+	
+	private static final Logger logger = LoggerFactory.getLogger(AreaHbConfigController.class);
+	
+	private IAreaHbConfigService areaHbConfigService =  enhance(AreaHbConfigServiceImpl.class);
+	
+	
+	public void specialArea(){
+		List<Record> find = Db.find("select * from t_product");
+		setAttr("products", find);
+		Map<Integer, Record> groupByStr = WxUtil.toMapInt(find, "type_");
+		setAttr("productMaps", JsonKit.toJson(groupByStr));
+		
+		List<Record> t_area = Db.find("select * from t_area");
+		setAttr("products", find);
+		setAttr("areas", t_area);
+		render("/pj/specailList.jsp");
+	}
+
+	public void specialAreaList(){
+		List<Record> find = Db.find("select s.id,area_name,p.name_ from special_area s left join t_product p on(p.type_ = s.type_) left join t_area a on(a.id=s.area_id)");
+		renderJson(find);
+	}
+	
+	public void addSpecialArea(){
+		String areas = getPara("areas");
+		String products = getPara("products");
+		StringBuilder sb = new StringBuilder();
+		String[] areaArr = areas.split(",");
+		String[] productArr = products.split(",");
+		Record result = new Record();
+		for (String productId : productArr) {
+			for (String areaId : areaArr) {
+				Record findFirst = Db.findFirst("select * from special_area where area_id = ? and type_ = ?",areaId,productId);
+				if(findFirst == null){
+					findFirst = new Record();
+					findFirst.set("area_id", areaId).set("type_", productId);
+					Db.save("special_area", findFirst);
+				}
+			}
+		}
+		result.set("status", true);
+		renderJson(result);
+	}
+	
+	public void delSpecialArea(){
+		String id = getPara("id");
+		Db.deleteById("special_area", id);
+		Record result = new Record();
+		result.set("status", true);
+		renderJson(result);
+	}
+	
+	public void areaList(){
+		int uid = getLoginUser().getId();
+		List<Record> plans = Db.find("select * from t_pj_plan where uid = "+uid+"   order by create_time desc");
+		setAttr("plans", plans);
+		List<Record> find = Db.find("select * from t_product where uid = "+uid+" ");
+		setAttr("products", find);
+		Map<Integer, Record> groupByStr = WxUtil.toMapInt(find, "type_");
+		setAttr("productMaps", JsonKit.toJson(groupByStr));
+		
+		List<Record> t_area = Db.find("select * from t_area where uid = "+uid+" ");
+		setAttr("products", find);
+		setAttr("areas", t_area);
+		 Map<Integer, Record> groupByInt = WxUtil.toMapInt(t_area, "id");
+		setAttr("areaMaps", JsonKit.toJson(groupByInt));
+		renderJsp("/pj/areaList.jsp");
+	}
+	
+	public void areaListQuery(){
+		int uid = getLoginUser().getId();
+		List<Record> find = Db.find("select l.*,p.plan_name from t_pj_area_list l left join t_pj_plan p on (l.plan_id=p.id) where l.uid = "+uid+"  order by l.create_time desc");
+		renderJson(find);
+	}
+	
+	public void saveAreaPlan(){
+		int uid = getLoginUser().getId();
+		String pid = getPara("pid");
+		String planId = getPara("planId");
+		String areas = getPara("areas");
+		String products = getPara("products");
+		if(WxUtil.isNull(pid) || pid.equals("-1")){
+			Record  areaPlan  =new Record();
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products).set("uid", uid);
+			Db.save("t_pj_area_list", areaPlan);
+			Integer areaPlanId = WxUtil.getInt("id", areaPlan);
+			pid = areaPlanId.toString();
+			
+		}else{
+			Record areaPlan = Db.findById("t_pj_area_list", pid);
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products).set("update_time", new Date());
+			Db.update("t_pj_area_list", areaPlan);
+			Db.update("delete from t_pj_area_detail where area_plan_id = ?",pid);
+		}
+		StringBuilder sb = new StringBuilder();
+		String[] areaArr = areas.split(",");
+		String[] productArr = products.split(",");
+		for (String product : productArr) {
+			for (String area : areaArr) {
+				if(sb.length()>0){
+					sb.append(",");
+				}
+				sb.append("("+area+",'"+product+"',"+planId+","+pid+","+uid+")");
+			}
+		}
+		Db.update("insert into t_pj_area_detail (area_id,product_type,plan_id,area_plan_id,uid) values "+sb);
+		ResultMsg rm  = new ResultMsg();
+		rm.setStatus(true);
+		renderJson(rm);
+	}
+	
+	
+	public void delAreaPlan(){
+		String pid = getPara("id");
+		Db.update("delete from t_pj_area_detail where area_plan_id = ?",pid);
+		Db.update("delete from t_pj_area_list where id = ?",pid);
+		ResultMsg resultMsg = new ResultMsg();
+		resultMsg.setStatus(true);
+		renderJson(resultMsg);
+	}
+	public void listPlans(){
+		int user_id = getLoginUser().getId();
+		List<Record> prizes = Db.find("select * from t_prize_shiwu where uid = ? ",user_id);
+		Map<Integer, Record> mapInt = WxUtil.toMapInt(prizes, "id");
+		setAttr("prizesMap", JsonKit.toJson(mapInt));
+		renderJsp("/pj/list.jsp");
+	}
+	
+	
+	public void listPlansQuery(){
+		AdminView loginUser = getLoginUser();
+		int user_id = loginUser.getId();
+		List<Record> find = Db.find("select * from t_pj_plan where uid = ? order by create_time desc",user_id);
+		Map<Integer,Record> maps = new HashMap<Integer,Record>();
+		StringBuilder sb  =new StringBuilder();
+		for (Record record : find) {
+			Integer id = WxUtil.getInt("id", record);
+			maps.put(id, record);
+			if(sb.length()>0){
+				sb.append(",");
+			}
+			sb.append(id);
+		}
+		List<Record> rates = Db.find("select * from t_hbrate where uid = ?",user_id);
+		Map<Integer, List<Record>> groupByInt = WxUtil.groupByInt(rates, "plan_id");
+		Set<Integer> keySet = groupByInt.keySet();
+		for (Integer integer : keySet) {
+			Record record = maps.get(integer);
+			List<Record> list = groupByInt.get(integer);
+			record.set("detail", list);
+		}
+		
+		renderJson(find);
+	}
+	private IHBRateService hbrateService = enhance(HBRateServiceImpl.class);
+	
+	public void planDetail(){
+		AdminView loginUser = getLoginUser();
+		int user_id = loginUser.getId();
+		Integer planId = getParaToInt("planId") == null?0:getParaToInt("planId");
+		List<Record> find = Db.find("select * from t_prize_shiwu where uid = ?",user_id);
+		setAttr("shiwuMap", find);
+		setAttr("shiwuList", JsonKit.toJson(find));
+		if(planId>0){
+			List<HBRate> view = hbrateService.getHBRateList(planId);
+			setAttr("scanView", view);
+			Record findById = Db.findById("t_pj_plan", planId);
+			setAttr("planName", findById.getStr("plan_name"));
+			setAttr("planId", planId);
+		}
+		renderJsp("/pj/planDetail.jsp");
+	}
+	public void saveHbrate(){
+		AdminView loginUser = getLoginUser();
+		
+		int id = loginUser.getId();
+		String[] money_ = getParaValues("money");
+		String[] rate_ = getParaValues("rate");
+		String[] prizeTYpes = getParaValues("prize_type");
+		Integer planId = getParaToInt("planId");
+		String planName = getPara("planName");
+		ResultMsg rm = hbrateService.saveHbrate(money_, rate_, planId,planName,prizeTYpes,id);
+//		CacheNotice.updateScan();
+		renderJson(rm);
+	}
+	
+	public void delRate(){
+		Integer planId = getParaToInt("id");
+		int is_del = getParaToInt("is_del");
+		if(is_del == 1){
+			is_del = 0;
+		}else{
+			is_del = 1;
+		}
+//		String planName = getPara("planName");
+		ResultMsg rm  = new ResultMsg();
+		int update = Db.update("update t_pj_plan set is_del = ? where id = ?",is_del,planId);
+//		ResultMsg rm = hbrateService.saveHbrate(money_, rate_, planId,planName);
+		if(update == 1){
+			rm.setStatus(true);
+		}
+		renderJson(rm);
+	}
+	public void listAreaHbSkip(){
+		List<Record> AreaHbConfigRecord = areaHbConfigService.findAreaHbConfig();
+		setAttr("area", AreaHbConfigRecord);
+		Integer id = -1;
+		if(!AreaHbConfigRecord.isEmpty()){
+			id = AreaHbConfigRecord.get(0).get("config_id");
+		}
+		setAttr("acId", id);
+		render("/page/AreaHbConfigList.jsp");
+	}
+	
+	public void listArea(){
+		renderJsp("/page/chooseDlg/area.jsp");
+	}
+
+	public void listAreaQuery(){
+		List<Record> find = Db.find("select * from t_area");
+		renderJson(find);
+	}
+	
+	public void listProduct(){
+		renderJsp("/page/chooseDlg/product.jsp");
+	}
+
+	public void listProductQuery(){
+		List<Record> find = Db.find("select type_ id, name_ from t_product");
+		renderJson(find);
+	}
+	
+	public void linkArea(){
+		Integer config_Id = getParaToInt("config_id");
+		String areas = getPara("areas");
+		Db.update("delete from t_qcode_hb_config_area where config_id = ?",config_Id);
+		if(!WxUtil.isNull(areas)){
+			String[] split = areas.split(",");
+			for (String string : split) {
+				Db.update("insert ignore into t_qcode_hb_config_area(area_id,config_id) values(?,?)",string,config_Id);
+			}
+		}
+		renderText("ok");
+	}
+	
+	public void linkProduct(){
+		Integer config_Id = getParaToInt("config_id");
+		String areas = getPara("products");
+		Db.update("delete from t_qcode_hb_config_product where config_id = ?",config_Id);
+		if(!WxUtil.isNull(areas)){
+			String[] split = areas.split(",");
+			for (String string : split) {
+				Db.update("insert ignore into t_qcode_hb_config_product(product_type,config_id) values(?,?)",string,config_Id);
+			}
+		}
+		renderText("ok");
+	}
+	
+	public void queryLinkArea(){
+		Integer config_Id = getParaToInt("config_id");
+		List<Record> find = Db.find("select a.*,h.area_name from t_qcode_hb_config_area a LEFT JOIN t_area h on (a.area_id = h.id) where config_id = ?",config_Id);
+		renderJson(find);
+	}
+
+	public void queryLinkProduct(){
+		Integer config_Id = getParaToInt("config_id");
+		List<Record> find = Db.find("select o.*,p.name_ from t_qcode_hb_config_product o LEFT JOIN t_product p on(o.product_type = p.type_) where config_id = ?",config_Id);
+		renderJson(find);
+	}
+	
+	
+	
+	
+	public void addAreaHbConfigInfoSkip(){
+		render("/page/addAreaHbConfig.jsp");
+	}
+	
+	public void findAreaHbConfigInfo(){
+		String aoData = getPara("aoData");
+		Integer config_Id = getParaToInt("config_Id");
+		String json = areaHbConfigService.findAreaHbConfig(aoData,config_Id);
+		renderJson(json);
+	}
+	
+	public void findAreaHbConfigRateInfo(){
+		Integer Id = getParaToInt("Id");
+		List<Record> AreaHbConfigRateRecord = areaHbConfigService.findAreaHbConfigRateById(Id);
+		renderJson(AreaHbConfigRateRecord);
+	}
+	
+	public void saveAreaHbConfigInfo(){
+		String area = getPara("area");
+		String times = getPara("times");
+		ResultMsg rm = areaHbConfigService.saveAreaHbConfigInfo(area,times);
+		renderJson(rm);
+	}
+	
+	public void saveAreaHbConfigRateInfo(){
+		String[] money_ = getParaValues("money_");
+		String[] rate_ = getParaValues("rate_");
+		Integer[] time_ids = getParaValuesToInt("time_id");		
+		ResultMsg rm = areaHbConfigService.saveAreaHbConfigRateInfo(money_,rate_,time_ids);
+		CacheNotice.updateScan();
+		renderJson(rm);
+	}
+	
+	public void deleteAreaHbConfigInfo(){
+		Integer configId = getParaToInt("configid");
+		ResultMsg rm =  areaHbConfigService.deleteAreaHbConfigInfo(configId);
+		renderJson(rm);
+	}
+	
+	public void deleteAreaHbConfigRateInfo(){
+		Integer Id = getParaToInt("Id");
+		ResultMsg rm =  areaHbConfigService.deleteAreaHbConfigRateInfo(Id);
+		renderJson(rm);
+	}
+}

+ 103 - 0
src/main/java/com/qlm/controller/pj/FirstZhongController.java

@@ -0,0 +1,103 @@
+package com.qlm.controller.pj;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 门店配奖
+ *
+ */
+@RequestUrl("/first")
+public class FirstZhongController extends CommonController{
+
+	public void areaList(){
+		int uid = getLoginUser().getId();
+		List<Record> plans = Db.find("select * from t_pj_plan where uid = "+uid+"  order by create_time desc");
+		setAttr("plans", plans);
+		List<Record> find = Db.find("select * from t_product where uid = "+uid+" ");
+		setAttr("products", find);
+		Map<Integer, Record> groupByStr = WxUtil.toMapInt(find, "type_");
+		setAttr("productMaps", JsonKit.toJson(groupByStr));
+		
+		List<Record> t_area = Db.find("select * from t_area where uid = "+uid+" ");
+		setAttr("products", find);
+		setAttr("areas", t_area);
+		 Map<Integer, Record> groupByInt = WxUtil.toMapInt(t_area, "id");
+		setAttr("areaMaps", JsonKit.toJson(groupByInt));
+		renderJsp("/pj/first/index.jsp");
+	}
+	
+	public void areaListQuery(){
+		int uid = getLoginUser().getId();
+		List<Record> find = Db.find("select l.*,p.plan_name from t_pj_first_list l left join t_pj_plan p on (l.plan_id=p.id) where l.uid = ? order by l.create_time desc",uid);
+		renderJson(find);
+	}
+	
+	public void saveAreaPlan(){
+		String pid = getPara("pid");
+		String planId = getPara("planId");
+		String areas = getPara("areas");
+		String startDate = getPara("startDate");
+		String endDate = getPara("endDate");
+		String products = getPara("products");
+		int uid = getLoginUser().getId();
+		if(WxUtil.isNull(pid) || pid.equals("-1")){
+			Record  areaPlan  =new Record();
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId).set("update_time", new Date())
+			.set("areas", areas).set("products", products).set("start_time", startDate)
+			.set("end_time", endDate).set("uid", uid);
+			Db.save("t_pj_first_list", areaPlan);
+			Integer areaPlanId = WxUtil.getInt("id", areaPlan);
+			pid = areaPlanId.toString();
+			
+		}else{
+			Record areaPlan = Db.findById("t_pj_first_list", pid);
+			areaPlan.set("update_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products).set("update_time", new Date()).set("start_time", startDate)
+			.set("end_time", endDate);
+			Db.update("t_pj_first_list", areaPlan);
+			Db.update("delete from t_pj_first_detail where area_plan_id = ?",pid);
+		}
+		StringBuilder sb = new StringBuilder();
+		String[] areaArr = areas.split(",");
+		String[] productArr = products.split(",");
+		for (String product : productArr) {
+			for (String area : areaArr) {
+				if(sb.length()>0){
+					sb.append(",");
+				}
+				sb.append("("+area+",'"+product+"',"+planId+","+pid+",'"+startDate+"','"+endDate+"')");
+			}
+		}
+		Db.update("insert into t_pj_first_detail (area_id,product_type,plan_id,area_plan_id,start_time,end_time) values "+sb);
+		ResultMsg rm  = new ResultMsg();
+		rm.setStatus(true);
+		renderJson(rm);
+	}
+	
+	
+	public void delAreaPlan(){
+		String pid = getPara("id");
+		Db.update("delete from t_pj_first_detail where area_plan_id = ?",pid);
+		Db.update("delete from t_pj_first_list where id = ?",pid);
+		ResultMsg resultMsg = new ResultMsg();
+		resultMsg.setStatus(true);
+		renderJson(resultMsg);
+	}
+}

+ 93 - 0
src/main/java/com/qlm/controller/pj/RetailPjController.java

@@ -0,0 +1,93 @@
+package com.qlm.controller.pj;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+
+/**
+ * 门店配奖
+ *
+ */
+@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+public class RetailPjController extends Controller{
+
+	public void areaList(){
+		List<Record> plans = Db.find("select * from t_pj_plan  order by create_time desc");
+		setAttr("plans", plans);
+		List<Record> find = Db.find("select * from t_product");
+		setAttr("products", find);
+		Map<Integer, Record> groupByStr = WxUtil.toMapInt(find, "type_");
+		setAttr("productMaps", JsonKit.toJson(groupByStr));
+		
+		List<Record> t_area = Db.find("select * from t_retail");
+		setAttr("products", find);
+		setAttr("areas", t_area);
+		 Map<Integer, Record> groupByInt = WxUtil.toMapInt(t_area, "id");
+		setAttr("areaMaps", JsonKit.toJson(groupByInt));
+		renderJsp("/pj/retail/retailList.jsp");
+	}
+	
+	public void areaListQuery(){
+		List<Record> find = Db.find("select l.*,p.plan_name from t_pj_retail_list l left join t_pj_plan p on (l.plan_id=p.id) order by l.create_time desc");
+		renderJson(find);
+	}
+	
+	public void saveAreaPlan(){
+		String pid = getPara("pid");
+		String planId = getPara("planId");
+		String areas = getPara("areas");
+		String products = getPara("products");
+		if(WxUtil.isNull(pid) || pid.equals("-1")){
+			Record  areaPlan  =new Record();
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products);
+			Db.save("t_pj_retail_list", areaPlan);
+			Integer areaPlanId = WxUtil.getInt("id", areaPlan);
+			pid = areaPlanId.toString();
+			
+		}else{
+			Record areaPlan = Db.findById("t_pj_retail_list", pid);
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products).set("update_time", new Date());
+			Db.update("t_pj_retail_list", areaPlan);
+			Db.update("delete from t_pj_retail_detail where area_plan_id = ?",pid);
+		}
+		StringBuilder sb = new StringBuilder();
+		String[] areaArr = areas.split(",");
+		String[] productArr = products.split(",");
+		for (String product : productArr) {
+			for (String area : areaArr) {
+				if(sb.length()>0){
+					sb.append(",");
+				}
+				sb.append("("+area+",'"+product+"',"+planId+","+pid+")");
+			}
+		}
+		Db.update("insert into t_pj_retail_detail (retail_id,product_type,plan_id,area_plan_id) values "+sb);
+		ResultMsg rm  = new ResultMsg();
+		rm.setStatus(true);
+		renderJson(rm);
+	}
+	
+	
+	public void delAreaPlan(){
+		String pid = getPara("id");
+		Db.update("delete from t_pj_retail_detail where area_plan_id = ?",pid);
+		Db.update("delete from t_pj_retail_list where id = ?",pid);
+		ResultMsg resultMsg = new ResultMsg();
+		resultMsg.setStatus(true);
+		renderJson(resultMsg);
+	}
+}

+ 93 - 0
src/main/java/com/qlm/controller/pj/YwyPjController.java

@@ -0,0 +1,93 @@
+package com.qlm.controller.pj;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import com.jfinal.aop.Before;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.interceptor.AdminOperate2Interceptor;
+import com.qlm.interceptor.AdminOperateInterceptor;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+
+/**
+ * 业务员配奖
+ *
+ */
+@Before({AdminOperateInterceptor.class,AdminOperate2Interceptor.class})
+public class YwyPjController extends Controller{
+
+	public void areaList(){
+		List<Record> plans = Db.find("select * from t_pj_plan  order by create_time desc");
+		setAttr("plans", plans);
+		List<Record> find = Db.find("select * from t_product");
+		setAttr("products", find);
+		Map<Integer, Record> groupByStr = WxUtil.toMapInt(find, "type_");
+		setAttr("productMaps", JsonKit.toJson(groupByStr));
+		
+		List<Record> t_area = Db.find("select * from t_ywy");
+		setAttr("products", find);
+		setAttr("areas", t_area);
+		 Map<Integer, Record> groupByInt = WxUtil.toMapInt(t_area, "id");
+		setAttr("areaMaps", JsonKit.toJson(groupByInt));
+		renderJsp("/pj/ywy/ywyList.jsp");
+	}
+	
+	public void areaListQuery(){
+		List<Record> find = Db.find("select l.*,p.plan_name from t_pj_ywy_list l left join t_pj_plan p on (l.plan_id=p.id) order by l.create_time desc");
+		renderJson(find);
+	}
+	
+	public void saveAreaPlan(){
+		String pid = getPara("pid");
+		String planId = getPara("planId");
+		String areas = getPara("areas");
+		String products = getPara("products");
+		if(WxUtil.isNull(pid) || pid.equals("-1")){
+			Record  areaPlan  =new Record();
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products);
+			Db.save("t_pj_ywy_list", areaPlan);
+			Integer areaPlanId = WxUtil.getInt("id", areaPlan);
+			pid = areaPlanId.toString();
+			
+		}else{
+			Record areaPlan = Db.findById("t_pj_ywy_list", pid);
+			areaPlan.set("create_time", new Date())
+			.set("is_del", 0).set("plan_id", planId)
+			.set("areas", areas).set("products", products).set("update_time", new Date());
+			Db.update("t_pj_ywy_list", areaPlan);
+			Db.update("delete from t_pj_ywy_detail where area_plan_id = ?",pid);
+		}
+		StringBuilder sb = new StringBuilder();
+		String[] areaArr = areas.split(",");
+		String[] productArr = products.split(",");
+		for (String product : productArr) {
+			for (String area : areaArr) {
+				if(sb.length()>0){
+					sb.append(",");
+				}
+				sb.append("("+area+",'"+product+"',"+planId+","+pid+")");
+			}
+		}
+		Db.update("insert into t_pj_ywy_detail (ywy_id,product_type,plan_id,area_plan_id) values "+sb);
+		ResultMsg rm  = new ResultMsg();
+		rm.setStatus(true);
+		renderJson(rm);
+	}
+	
+	
+	public void delAreaPlan(){
+		String pid = getPara("id");
+		Db.update("delete from t_pj_ywy_detail where area_plan_id = ?",pid);
+		Db.update("delete from t_pj_ywy_list where id = ?",pid);
+		ResultMsg resultMsg = new ResultMsg();
+		resultMsg.setStatus(true);
+		renderJson(resultMsg);
+	}
+}

+ 129 - 0
src/main/java/com/qlm/controller/shanghu/ShanghuController.java

@@ -0,0 +1,129 @@
+package com.qlm.controller.shanghu;
+
+import java.util.List;
+
+import sun.security.provider.MD5;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.controller.editor.service.EditorService;
+import com.qlm.controller.shanghu.service.BillServcie;
+import com.qlm.tools.MD5Utils;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+
+@RequestUrl("/shanghu")
+public class ShanghuController extends CommonController{
+	
+	private BillServcie billService = enhance(BillServcie.class);
+
+	@Override
+	protected String getPath(String key) {
+		if("bill".equals(key)){
+			AdminView admin = getSessionAttr("adminView");
+			int id = admin.getId();
+			Record t_user_balance = Db.findById("t_user_balance","user_id", id);
+			String balance = "0";
+			if(t_user_balance != null){
+				Integer balance1 = WxUtil.getInt("balance", t_user_balance,0);
+				balance = WxUtil.hbValue(balance1);
+			}
+			setAttr("balance", balance);
+			return "/shanghu/bill.jsp";
+		}
+		return "/shanghu/index.jsp";
+	}
+
+	@Override
+	protected String getTableName(String key) {
+		if("bill".equals(key)){
+			return "t_user_bill";
+		}
+		return "t_admin";
+	}
+	
+	
+
+	@Override
+	protected void formatData(String tableName, List<Record> find) {
+		if("t_admin".equals(tableName)){
+			for (Record record : find) {
+				Integer id = WxUtil.getInt("id", record);
+				Record t_user_balance = Db.findById("t_user_balance","user_id", id);
+				if(t_user_balance != null){
+					Integer balance = WxUtil.getInt("balance", t_user_balance,0);
+					String hbValue = WxUtil.hbValue(balance);
+					record.set("balance", hbValue);
+					
+				}else{
+					record.set("balance", 0);
+				}
+			}
+		}else if("t_user_bill".equals(tableName)){
+			for (Record record : find) {
+				Integer id = WxUtil.getInt("user_id", record);
+				Record user = Db.findById("t_admin", id);
+				if(user != null){
+					String name = user.getStr("name_");
+					record.set("name", name);
+					
+				}
+			}
+		}
+	}
+
+	@Override
+	protected void checkData(String tableName, Record data) {
+		if("t_admin".equals(tableName)){
+			String username = data.getStr("username");
+			Record findFirst = Db.findFirst("select * from t_admin where username = ?",username);
+			if(findFirst != null){
+				throw new RuntimeException("该用户名已经存在");
+			}
+		}
+		super.checkData(tableName, data);
+	}
+
+	@Override
+	protected void beforeSave(String tableName, Record data) {
+		if("t_admin".equals(tableName)){
+			AdminView loginUser = getLoginUser();
+			String tel = data.get("tel_");
+			if(loginUser.getLevel() == 1){
+				if(!WxUtil.isNull(tel)){
+					String md5 = MD5Utils.MD5(tel.substring(5)).toLowerCase();
+					data.set("password", md5);
+					data.set("level", 2);
+				}
+			}
+		}
+	
+		
+	
+		// TODO Auto-generated method stub
+		super.beforeSave(tableName, data);
+	}
+	
+	
+	@Override
+	protected void afterSave(String tableName, Record data) {
+		if("t_admin".equals(tableName)){
+			Integer id = WxUtil.getInt("id", data);
+			EditorService.cloneTemplate(id);
+		}
+		super.afterSave(tableName, data);
+	}
+
+	public void modifyMoney(){
+		int userId = getParaToInt("userId");
+		int money = getParaToInt("money");
+		int type = getParaToInt("type");
+		ResultMsg modifyMoney = billService.modifyMoney(userId, money, type);
+		renderJson(modifyMoney);
+	}
+
+    
+}

+ 73 - 0
src/main/java/com/qlm/controller/shanghu/service/BillServcie.java

@@ -0,0 +1,73 @@
+package com.qlm.controller.shanghu.service;
+
+import java.util.Date;
+
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+
+public class BillServcie {
+
+	/**
+	 * 
+	 * @param userId 用户ID
+	 * @param money 金额
+	 * @param type 1减少 2增加
+	 */
+	@Before(Tx.class)
+	public ResultMsg modifyMoney(int userId,int money ,int type){
+		money = money*100;
+		ResultMsg resultMsg = new ResultMsg();
+		boolean status = false;
+		String msg = "";
+		if(money == 0){
+			msg = "金额不能为空";
+			resultMsg.setMsg(msg);
+			return resultMsg;
+		}
+		long newVersion = System.currentTimeMillis();
+		Record t_user_balance = Db.findFirst("select * from t_user_balance where user_id = ?",userId);
+		if(t_user_balance != null){
+			String oldVersion = t_user_balance.getStr("version");
+			if(type == 1){
+				int update = Db.update("update t_user_balance set balance = balance-"+money +" ,version = ? where user_id = ? and version = ? and balance>="+money,newVersion,userId,oldVersion);
+				if(update == 1){
+					status = true;
+				}else{
+					msg = "修改失败";
+				}
+			}else{
+				int update = Db.update("update t_user_balance set balance = balance+"+money +" ,version = ? where user_id = ? and version = ?",newVersion,userId,oldVersion);
+				if(update == 1){
+					status = true;
+				}else{
+					msg = "修改失败";
+				}
+			}
+		}else{
+			if(type == 1){
+				msg = "余额不足";
+			}else{
+				Record info = new Record();
+				info.set("user_id", userId).set("balance", money).set("version", newVersion);
+				Db.save("t_user_balance", info);
+				status = true;
+			}
+		}
+		if(status){
+			Record jilu = new Record();
+			t_user_balance = Db.findFirst("select * from t_user_balance where user_id = ?",userId);
+			Object balance = t_user_balance.get("balance");
+			jilu.set("create_time", new Date()).set("amount", money).set("user_id",userId)
+			.set("balance", balance).set("type_", type);
+			resultMsg.set("balance", WxUtil.hbValue(WxUtil.parseInt(balance+"")));
+			Db.save("t_user_bill", jilu);
+		}
+		resultMsg.setMsg(msg);
+		resultMsg.setStatus(status);
+		return resultMsg;
+	}
+}

+ 98 - 0
src/main/java/com/qlm/controller/system/ResController.java

@@ -0,0 +1,98 @@
+package com.qlm.controller.system;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Enhancer;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.entity.Res;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IResService;
+import com.qlm.service.impl.ResServiceImpl;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 菜单管理
+ * @author lds
+ * @Date 2019-03-18
+ *
+ */
+@RequestUrl("/res")
+public class ResController extends Controller {
+	
+	private IResService resService = Enhancer.enhance(ResServiceImpl.class);
+	
+	public void index(){
+		renderJsp("/page/res/resManager.jsp");
+	}
+	
+	public void getMenuTree(){
+		String jsonStr = resService.getMenuTree();
+		Record r = new Record();
+		if(jsonStr != null){
+			r.set("tree", jsonStr);
+			r.set("status", true);
+		}else{
+			r.set("status", false);
+			r.set("msg", "菜单树为空");
+		}
+		renderJson(r);
+	}
+	
+	public void getResList(){
+		renderJson(resService.getResList());
+	}
+	
+	public void addRes(){
+		renderJsp("/page/res/addRes.jsp");
+	}
+	
+	public void add(){
+		Record r = new Record();
+		Res res = getModel(Res.class,"res");
+		AdminView admin = getSessionAttr("adminView");
+		boolean result = resService.add(res);
+		if(result){
+			r.set("status", true);
+			r.set("msg", "添加菜单成功");
+		}else{
+			r.set("status", false);
+			r.set("msg", "添加菜单失败");
+		}
+		renderJson(r);
+	}
+	
+	public void del(){
+		Record r = new Record();
+		Integer id = getParaToInt("id",0);
+		boolean rs = resService.del(id);
+		if(rs){
+			r.set("status", true);
+			r.set("msg", "删除成功");
+		}else{
+			r.set("status", false);
+			r.set("msg", "删除失败");
+		}
+		renderJson(r);
+	}
+	
+	public void updateRes(){
+		Integer id = getParaToInt(0,0);
+		Record res = resService.getById(id);
+		setAttr("res",res);
+		renderJsp("/page/res/updateRes.jsp");
+	}
+	
+	public void update(){
+		Record r = new Record();
+		boolean result = getModel(Res.class,"res").update();
+		if(result){
+			r.set("status", true);
+			r.set("msg", "更新菜单成功");
+		}else{
+			r.set("status", false);
+			r.set("msg", "更新菜单失败");
+		}
+		renderJson(r);
+	}
+}

+ 159 - 0
src/main/java/com/qlm/controller/system/RoleController.java

@@ -0,0 +1,159 @@
+package com.qlm.controller.system;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Enhancer;
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IRoleService;
+import com.qlm.service.impl.RoleServiceImpl;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 角色管理
+ * @author lds
+ * @Date 2019-03-15
+ *
+ */
+@RequestUrl("/role")
+public class RoleController extends CommonController {
+	
+	private IRoleService roleService = Enhancer.enhance(RoleServiceImpl.class);
+	
+	public void index(){
+		renderJsp("/page/role/rolesManager.jsp");
+	}
+	
+	public void getRoleList(){
+		AdminView loginUser = getLoginUser();
+		renderJson(roleService.getRolesList(loginUser));
+	}
+	
+	public void addRole(){
+		String roleName = getPara("rolename","");
+		boolean ex = roleService.getRoleByName(roleName);
+		Record r = new Record();
+		if(ex){
+			boolean result = roleService.save(roleName,getLoginUser());
+			if(result){
+				r.set("status", true);
+				r.set("msg", "添加角色成功");
+			}else{
+				r.set("status", false);
+				r.set("msg", "添加角色失败");
+			}
+		}else{
+			r.set("status", false);
+			r.set("msg", "不能添加重复的角色");
+		}
+		renderJson(r);
+	}
+	
+	public void getAuth(){
+		Integer roleId = getParaToInt("id",0);
+		Record r = roleService.getRoleById(roleId);
+		if(r == null){
+			renderHtml("<h3>角色不存在</h3>");
+			return;
+		}
+		StringBuilder builder = new StringBuilder();
+		builder.append("<input id=\"selectRoleId\" type=\"hidden\" name=\"selectRoleId\" value=\""+roleId+"\"/>");
+		builder.append("<ul id=\"role_menu_tree\" class=\"ztree\"></ul>");
+		String contextPath = getRequest().getContextPath();
+		builder.append("<script src=\""+contextPath+"/role/menujs\"></script>");
+		renderHtml(builder.toString());
+	}
+	
+	public void getAuthById(){
+		Integer roleId = getParaToInt("id",0);
+		Record r = roleService.getRoleById(roleId);
+		if(r == null){
+			renderHtml("<h3>角色不存在</h3>");
+			return;
+		}
+		String jsonStr = roleService.getAuthById(roleId);
+		renderJson(jsonStr);
+	}
+	
+	public void updateRoleAuth(){
+		String[] auths = getParaValues("checkedNodes[]");
+		Integer roleId = getParaToInt("roleId",0);
+		Record r = new Record();
+		if(auths == null || roleId == null){
+			r.set("status", false);
+			r.set("msg", "参数不正确");
+		}else{
+			boolean result = roleService.saveRoleAuth(auths, roleId);
+			if(result){
+				r.set("status", true);
+				r.set("msg", "角色授权成功");
+			}else{
+				r.set("status", false);
+				r.set("msg", "角色授权失败");
+			}
+		}
+		renderJson(r);
+	}
+	
+	public void menujs(){
+		//renderJavascript("alert($(\"#role_menu_tree\").length>0);");//有效,可执行
+		render("/page/role/initMenu.html");
+	}
+	
+	public void getRoleById(){
+		Integer id = getParaToInt("id",0);
+		Record r = roleService.getRoleById(id);
+		if(r == null){
+			renderHtml("<h3>角色不存在</h3>");
+			return;
+		}
+		StringBuilder builder = new StringBuilder();
+		builder.append("<div class=\"ibox-content\">");
+		builder.append("<form class=\"form-horizontal wrapper-content\" method=\"post\">");
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>角色名称:</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<input class=\"form-control\" type=\"text\" name=\"role_name\" id=\"role_name\"  value=\""+r.getStr("role_name")+"\"/>");
+		builder.append("</div>");
+		builder.append("</div>");
+		builder.append("</form>");
+		builder.append("</div>");
+
+		renderHtml(builder.toString());
+	}
+	
+	public void updateRole(){
+		Record role = new Record();
+		Record r = new Record();
+		Integer id = getParaToInt("id",0);
+		String role_name = getPara("rolename","");
+		role.set("id", id);
+		role.set("role_name", role_name);
+		boolean result = roleService.updateRole(role);
+		if(result){
+			r.set("status", true);
+			r.set("msg", "更新角色成功");
+		}else{
+			r.set("status", false);
+			r.set("msg", "更新角色失败");
+		}
+		renderJson(r);
+	}
+	
+	public void delRole(){
+		Integer id = getParaToInt("id",0);
+		boolean result = roleService.delRole(id);
+		Record r = new Record();
+		if(result){
+			r.set("status", true);
+			r.set("msg", "删除角色成功");
+		}else{
+			r.set("status", true);
+			r.set("msg", "删除角色失败");
+		}
+		renderJson(r);
+	}
+
+}

+ 255 - 0
src/main/java/com/qlm/controller/system/UserController.java

@@ -0,0 +1,255 @@
+package com.qlm.controller.system;
+
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Enhancer;
+import com.jfinal.core.Controller;
+import com.jfinal.kit.HashKit;
+import com.jfinal.kit.StrKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.common.CommonController;
+import com.qlm.interceptor.AuthInterceptor;
+import com.qlm.service.IAdminService;
+import com.qlm.service.IRoleService;
+import com.qlm.service.impl.IAdminServiceImpl;
+import com.qlm.service.impl.RoleServiceImpl;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 用户管理
+ * @author lds
+ * @Date 2019-03-15
+ *
+ */
+@RequestUrl("/user")
+public class UserController extends CommonController {
+	private IAdminService userService = Enhancer.enhance(IAdminServiceImpl.class);
+
+	private IRoleService roleService = Enhancer.enhance(RoleServiceImpl.class);
+	
+	public void index(){
+		renderJsp("/page/user/usersManager.jsp");
+	}
+	
+	public void getUserList(){
+		renderJson(userService.getUsersList());
+	}
+	
+	public void add(){
+		List<Record> roles = roleService.getAllRoles();
+		StringBuilder builder = new StringBuilder();
+		builder.append("<div class=\"ibox-content\">");
+		builder.append("<form class=\"form-horizontal wrapper-content\" method=\"post\">");
+		
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>用户名称:</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<input class=\"form-control\" type=\"text\" name=\"username\" id=\"username\" />");
+		builder.append("</div>");
+		builder.append("</div>");
+		
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>密码:</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<input class=\"form-control\" type=\"password\" name=\"pass\" id=\"pass\"  />");
+		builder.append("</div>");
+		builder.append("</div>");
+		
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>确认密码:</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<input class=\"form-control\" type=\"password\" name=\"password\" id=\"confirpass\"  />");
+		builder.append("</div>");
+		builder.append("</div>");
+		
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>选择用户角色(单选):</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<select data-placeholder=\"选择角色\"  name=\"role\" id=\"role\" class=\"form-control\"  tabindex=\"2\">");
+		if(roles != null && roles.size()>0){
+			for(Record role:roles){
+				Integer roleId = WxUtil.getInt("id", role);
+				builder.append("<option value=\""+roleId+"\" hassubinfo=\"true\">"+role.getStr("role_name")+"</option>");
+			}
+		}else{
+			builder.append("<option value=\"\">请先添加角色</option>");
+		}
+
+		builder.append("</select>");
+		builder.append("</div>");
+		builder.append("</div>");
+
+		builder.append("</form>");
+		builder.append("</div>");
+		renderHtml(builder.toString());
+	}
+	
+	public void addUser(){
+		String username = getPara("username");
+		String pass = getPara("pass");
+		Integer role = getParaToInt("role",2);
+		Record r = new Record();
+		if(StrKit.isBlank(username) || StrKit.isBlank(pass)){
+			r.set("status", false);
+			r.set("msg", "用户名或密码不能为空");
+		}else{
+			Record user = new Record();
+			user.set("username", username);
+			user.set("password", HashKit.md5(pass));
+			user.set("role", role);
+//			user.set("create_time", new Date());
+			user.set("status", 1);
+			boolean result = userService.save(user);
+			if(result){
+				Record user_role = Db.findById("t_role",role);
+				if(user_role != null){
+					user.set("rolename", user_role.getStr("role_name"));
+				}
+				r.set("status", true);
+				r.set("user", user);
+				r.set("msg", "添加成功");
+			}else{
+				r.set("status", false);
+				r.set("msg", "添加失败");
+			}
+		}
+		renderJson(r);
+	}
+	
+	public void enableUser(){
+		Integer id = getParaToInt("id",0);
+		Record r = new Record();
+		boolean result = userService.enableUser(id);
+		if(result){
+			r.set("status", true);
+			r.set("msg", "激活成功");
+		}else{
+			r.set("status", false);
+			r.set("msg", "激活失败");
+		}
+		renderJson(r);
+	}
+	
+	public void disableUser(){
+		Integer id = getParaToInt("id",0);
+		AdminView account = getSessionAttr("adminView");
+		Record r = new Record();
+		if(id == 8){
+			r.set("status", false);
+			r.set("msg", "不能锁定超级管理员");
+		}else if(id == account.getId()){
+			r.set("status", false);
+			r.set("msg", "不能锁定自己");
+		}else{
+			boolean result = userService.disableUser(id);
+			if(result){
+				r.set("status", true);
+				r.set("msg", "锁定成功");
+			}else{
+				r.set("status", true);
+				r.set("msg", "锁定失败");
+			}
+		}
+		renderJson(r);
+	}
+	
+	public void getUserById(){
+		Integer id = getParaToInt("id",0);
+		Record user = userService.getUserById(id);
+		if(user == null){
+			renderHtml("<h3>不存在的用户</h3>");
+			return;
+		}
+		List<Record> roles = roleService.getAllRoles();
+		StringBuilder builder = new StringBuilder();
+		builder.append("<div class=\"ibox-content\">");
+		builder.append("<form class=\"form-horizontal wrapper-content\" method=\"post\">");
+		
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>用户名称:</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<input class=\"form-control\" type=\"text\" name=\"username\" value=\""+user.getStr("username")+"\" id=\"username\" />");
+		builder.append("</div>");
+		builder.append("</div>");
+
+		builder.append("<div class=\"form-group\">");
+		builder.append("<label class=\"col-sm-4 control-label\"><span class=\"text-danger\">*</span>选择用户角色(单选):</label>");
+		builder.append("<div class=\"col-sm-5\">");
+		builder.append("<select data-placeholder=\"选择角色\"  name=\"role\" id=\"role\" class=\"form-control\"  tabindex=\"2\">");
+		if(roles != null && roles.size()>0){
+			for(Record role:roles){
+				int roleId = WxUtil.getInt("id", role);
+				int userRoleid = WxUtil.getInt("role", user);
+				if(roleId == userRoleid){
+					builder.append("<option value=\""+roleId+"\" selected=\"selected\" hassubinfo=\"true\">"+role.getStr("role_name")+"</option>");
+				}else{
+					builder.append("<option value=\""+roleId+"\" hassubinfo=\"true\">"+role.getStr("role_name")+"</option>");
+				}
+				
+			}
+		}else{
+			builder.append("<option value=\"\">请先添加角色</option>");
+		}
+
+		builder.append("</select>");
+		builder.append("</div>");
+		builder.append("</div>");
+
+		builder.append("</form>");
+		builder.append("</div>");
+		renderHtml(builder.toString());
+	}
+	
+	public void updateUser(){
+		Integer id = getParaToInt("id",0);
+		Record r = new Record();
+		Record user = userService.getUserById(id);
+		String username = getPara("username");
+		Integer role = getParaToInt("role",2);
+		if(user == null){
+			r.set("status", false);
+			r.set("msg", "不存在的用户");
+		}else{
+			if(StrKit.isBlank(username)){
+				r.set("status", false);
+				r.set("msg", "用户名称不能为空");
+			}else{
+				user.set("username", username);
+				user.set("role", role);
+				boolean result = userService.updateUser(user);
+				if(result){
+					r.set("status", true);
+					Record user_role = Db.findById("t_role",role);
+					if(user_role != null){
+						user.set("rolename", user_role.getStr("role_name"));
+					}
+					r.set("user", user);
+					r.set("msg", "更新用户成功");
+				}else{
+					r.set("status", false);
+					r.set("msg", "更新用户失败");
+				}
+			}
+		}
+		renderJson(r);
+	}
+	
+	public void delUser(){
+		Integer id = getParaToInt("id",0);
+		Record r = new Record();
+		boolean result = userService.delUser(id);
+		if(result){
+			r.set("status", true);
+			r.set("msg", "删除成功");
+		}else{
+			r.set("status", true);
+			r.set("msg", "删除失败");
+		}
+		renderJson(r);
+	}
+	
+}

+ 10 - 0
src/main/java/com/qlm/entity/Admin.java

@@ -0,0 +1,10 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class Admin extends Model<Admin>{
+
+	private static final long serialVersionUID = 1L;
+	public static final Admin adminDao = new Admin();
+
+}

+ 13 - 0
src/main/java/com/qlm/entity/AreaHbConfig.java

@@ -0,0 +1,13 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class AreaHbConfig extends Model<AreaHbConfig> {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	
+	public static final AreaHbConfig areaHbConfig = new AreaHbConfig();
+}

+ 14 - 0
src/main/java/com/qlm/entity/AreaHbConfigRate.java

@@ -0,0 +1,14 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class AreaHbConfigRate extends Model<AreaHbConfigRate> {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	
+	public static final AreaHbConfigRate areaHbConfigRate = new AreaHbConfigRate();
+	
+}

+ 10 - 0
src/main/java/com/qlm/entity/CreateQrcodeRecord.java

@@ -0,0 +1,10 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class CreateQrcodeRecord extends Model<CreateQrcodeRecord>{
+
+	private static final long serialVersionUID = 1L;
+	public static final CreateQrcodeRecord dao = new CreateQrcodeRecord();
+
+}

+ 30 - 0
src/main/java/com/qlm/entity/DayHbEntity.java

@@ -0,0 +1,30 @@
+package com.qlm.entity;
+
+/**
+ * @author nommpp
+ * @date 2020/1/7
+ */
+public class DayHbEntity {
+    private int hb;
+    private int hbCount;
+
+    public int getHb() {
+        return hb;
+    }
+
+    public void setHb(int hb) {
+        this.hb = hb;
+    }
+
+    public int getHbAmount() {
+        return this.hb*this.hbCount;
+    }
+
+    public int getHbCount() {
+        return hbCount;
+    }
+
+    public void setHbCount(int hbCount) {
+        this.hbCount = hbCount;
+    }
+}

+ 10 - 0
src/main/java/com/qlm/entity/HBRate.java

@@ -0,0 +1,10 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class HBRate extends Model<HBRate>{
+
+	private static final long serialVersionUID = 1L;
+	public static final HBRate dao = new HBRate();
+
+}

+ 26 - 0
src/main/java/com/qlm/entity/HbEntity.java

@@ -0,0 +1,26 @@
+package com.qlm.entity;
+
+/**
+ * @author nommpp
+ * @date 2020/1/7
+ */
+public class HbEntity {
+    private int hbAmount;
+    private int hbCount;
+
+    public int getHbAmount() {
+        return hbAmount;
+    }
+
+    public void setHbAmount(int hbAmount) {
+        this.hbAmount = hbAmount;
+    }
+
+    public int getHbCount() {
+        return hbCount;
+    }
+
+    public void setHbCount(int hbCount) {
+        this.hbCount = hbCount;
+    }
+}

+ 12 - 0
src/main/java/com/qlm/entity/Log.java

@@ -0,0 +1,12 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class Log extends Model<Log>{
+	
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 7405689585041261792L;
+	public static final Log logDao = new Log();
+}

+ 8 - 0
src/main/java/com/qlm/entity/Master.java

@@ -0,0 +1,8 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class Master extends Model<Master>{
+	private static final long serialVersionUID = 6017936752087535568L;
+	public static final Master dao = new Master();
+}

+ 13 - 0
src/main/java/com/qlm/entity/Record.java

@@ -0,0 +1,13 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class Record extends Model<Record> {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	public static Record dao = new Record();
+	
+}

+ 16 - 0
src/main/java/com/qlm/entity/Res.java

@@ -0,0 +1,16 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+/**
+ * @author Administrator
+ */
+public class Res extends Model<Res> {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -3560109008956823734L;
+	
+
+}

+ 10 - 0
src/main/java/com/qlm/entity/ScanDetail.java

@@ -0,0 +1,10 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class ScanDetail extends Model<ScanDetail>{
+
+	private static final long serialVersionUID = 1L;
+	public static final ScanDetail dao = new ScanDetail();
+
+}

+ 35 - 0
src/main/java/com/qlm/entity/ScanHbEntity.java

@@ -0,0 +1,35 @@
+package com.qlm.entity;
+
+/**
+ * @author nommpp
+ * @date 2020/1/7
+ */
+public class ScanHbEntity {
+    private int scanCount;
+    private int hbAmount;
+    private int hbCount;
+
+    public int getScanCount() {
+        return scanCount;
+    }
+
+    public void setScanCount(int scanCount) {
+        this.scanCount = scanCount;
+    }
+
+    public int getHbAmount() {
+        return hbAmount;
+    }
+
+    public void setHbAmount(int hbAmount) {
+        this.hbAmount = hbAmount;
+    }
+
+    public int getHbCount() {
+        return hbCount;
+    }
+
+    public void setHbCount(int hbCount) {
+        this.hbCount = hbCount;
+    }
+}

+ 10 - 0
src/main/java/com/qlm/entity/ScanRecord.java

@@ -0,0 +1,10 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class ScanRecord extends Model<ScanRecord> {
+
+	private static final long serialVersionUID = 1L;
+	public static final ScanRecord recordDao = new ScanRecord();
+
+}

+ 10 - 0
src/main/java/com/qlm/entity/User.java

@@ -0,0 +1,10 @@
+package com.qlm.entity;
+
+import com.jfinal.plugin.activerecord.Model;
+
+public class User extends Model<User>{
+
+	private static final long serialVersionUID = 1L;
+	public static final User dao = new User();
+
+}

+ 33 - 0
src/main/java/com/qlm/interceptor/AdminOperate2Interceptor.java

@@ -0,0 +1,33 @@
+package com.qlm.interceptor;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+import com.jfinal.core.Controller;
+import com.qlm.view.core.AdminView;
+/**
+ * 记录操作日志拦截器
+ * @author Administrator
+ *
+ */
+public class AdminOperate2Interceptor implements Interceptor{
+	protected final static Logger      logger = LoggerFactory.getLogger(AdminOperate2Interceptor.class);
+	@Override
+	public void intercept(Invocation inv) {		
+		Controller controller = inv.getController();
+		AdminView admin = inv.getController().getSessionAttr("adminView");
+		if(admin == null){
+			controller.renderJsp("/page/unauthorized.jsp");
+			return;
+		}
+		int roleId = admin.getRoleId();
+		if(roleId==1 || roleId==2 || roleId==3 || roleId == 0 || roleId == -1){
+			inv.invoke();
+		}else{
+			controller.renderJsp("/page/unauthorized.jsp");
+		}
+	}
+}

+ 77 - 0
src/main/java/com/qlm/interceptor/AdminOperateInterceptor.java

@@ -0,0 +1,77 @@
+package com.qlm.interceptor;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Enhancer;
+import com.jfinal.aop.Interceptor;
+import com.jfinal.aop.Invocation;
+import com.qlm.common.Define;
+import com.qlm.service.IOperatingService;
+import com.qlm.service.impl.OperatingServiceImpl;
+import com.qlm.view.core.AdminView;
+/**
+ * 记录操作日志拦截器
+ * @author Administrator
+ *
+ */
+public class AdminOperateInterceptor implements Interceptor{
+	protected final static Logger       logger = LoggerFactory.getLogger(AdminOperateInterceptor.class);
+	
+	IOperatingService operatingService = Enhancer.enhance(OperatingServiceImpl.class);
+	
+	@Override
+	public void intercept(Invocation inv) {		
+		AdminView operating = null;
+		//操作IP
+		String ipAddr = inv.getController().getRequest().getRemoteAddr();
+		if(ipAddr.equals("0:0:0:0:0:0:0:1")){
+			ipAddr = "127.0.0.1";
+		}
+		operating = inv.getController().getSessionAttr("adminView");
+		if(operating == null){
+			operating = new AdminView();
+		}
+		int roleId = operating.getRoleId();
+		String op =inv.getMethodName();
+		if(Define.ROLE_ADMIN == roleId){//普通管理员
+			if("qrCodeAdd".equals(op) ){
+				return;//没有权限
+			} 
+		}else if(Define.ROLE_MANAGE == roleId){//超级管理员
+			if("qrCodeAdd".equals(op)){
+				return;//没有权限
+			} 
+		}
+		inv.invoke();
+		//当前登陆的操作人
+		operating = inv.getController().getSessionAttr("adminView");
+		if(operating==null ){
+			return;
+		}else{
+			if(Define.ROLE_DEVELOP != operating.getRoleId() ){
+				String str = "";
+				switch (inv.getMethodName()) {
+				case "login":
+					str = "登陆操作";
+					break;
+				case "saveHbrate":
+					str = "修改红包概率配置";
+					break;
+				case "qrCodeAdd"://生成二维码
+					str = "生成二维码";
+					break;
+				case "updPwd":
+					str = "修改密码";
+					break;
+				default:
+					break;
+				}
+				if(!"".equals(str)){
+					operatingService.OperatingRecord(operating.getUsername(),str, ipAddr);
+				}
+			}
+		}
+	}
+}

+ 42 - 0
src/main/java/com/qlm/interceptor/AuthInterceptor.java

@@ -0,0 +1,42 @@
+/**登陆拦截器
+ * @author David
+ *
+ */
+package com.qlm.interceptor;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Invocation;
+import com.jfinal.core.Controller;
+import com.qlm.view.core.AdminView;
+
+public class AuthInterceptor implements com.jfinal.aop.Interceptor {
+	protected final static Logger logger = LoggerFactory.getLogger(AuthInterceptor.class);
+	
+	public static String status_session_out = "session_out_qlm";//session超时返回前台状态
+
+	@Override
+	public void intercept(Invocation inv) {
+		Controller controller = inv.getController();
+		AdminView admin = controller.getSessionAttr("adminView");
+		if (admin != null) {
+			inv.invoke();
+		} else {
+			if(isAjaxReq(controller.getRequest())){
+				controller.renderJson(status_session_out);
+			}else{
+				controller.redirect("/login");
+			}
+		}
+
+	}
+
+	private boolean isAjaxReq(HttpServletRequest req) {
+		boolean ajax = "XMLHttpRequest".equals(req.getHeader("X-Requested-With"));
+		return ajax;
+	}
+
+}

+ 144 - 0
src/main/java/com/qlm/jfinal/JfinalConfig.java

@@ -0,0 +1,144 @@
+package com.qlm.jfinal;
+
+import java.util.List;
+
+import com.alibaba.druid.wall.WallFilter;
+import com.jfinal.config.Constants;
+import com.jfinal.config.Handlers;
+import com.jfinal.config.Interceptors;
+import com.jfinal.config.JFinalConfig;
+import com.jfinal.config.Plugins;
+import com.jfinal.config.Routes;
+import com.jfinal.core.Controller;
+import com.jfinal.ext.handler.ContextPathHandler;
+import com.jfinal.ext.plugin.quartz.QuartzPlugin;
+import com.jfinal.kit.PropKit;
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.druid.DruidPlugin;
+//import com.jfinal.plugin.ehcache.EhCachePlugin;
+import com.jfinal.render.ViewType;
+import com.qlm.annotation.RequestUrl;
+import com.qlm.controller.AuthController;
+import com.qlm.entity.Admin;
+import com.qlm.entity.AreaHbConfig;
+import com.qlm.entity.AreaHbConfigRate;
+import com.qlm.entity.HBRate;
+import com.qlm.entity.Log;
+import com.qlm.entity.Master;
+import com.qlm.entity.Record;
+import com.qlm.entity.Res;
+import com.qlm.entity.ScanRecord;
+import com.qlm.entity.User;
+import com.qlm.log.LogerFactory;
+import com.qlm.tongji.entity.Summary;
+import com.qlm.tools.core.ClassUtil;
+//import com.qlm.controller.IndexController;
+
+public class JfinalConfig extends JFinalConfig {
+	
+	@Override
+	public void configConstant(Constants me) {
+		me.setDevMode(false);
+		me.setViewType(ViewType.JSP);
+		me.setLogFactory(new LogerFactory());
+		PropKit.use("config.properties");
+	}
+
+	@Override
+	public void configHandler(Handlers me) {
+		me.add(new ContextPathHandler("ctx")); 
+	}
+
+	@Override
+	public void configInterceptor(Interceptors me) {
+
+	}
+
+	@Override
+	public void configPlugin(Plugins me) {	
+	  //配置数据库连接池插件
+        DruidPlugin dbPlugin=new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
+        // 加强数据库安全
+        WallFilter wallFilter = new WallFilter();
+        wallFilter.setDbType("mysql");
+        dbPlugin.addFilter(wallFilter);
+        // 添加 StatFilter 才会有统计数据
+        //dbPlugin.addFilter(new StatFilter());
+        me.add(dbPlugin);
+        
+     // 配置ActiveRecord插件
+        ActiveRecordPlugin arp = new ActiveRecordPlugin(dbPlugin);
+        me.add(arp);
+		
+		/** 定时任务插件**/
+		QuartzPlugin quartzPlugin =  new QuartzPlugin("job.properties");
+		me.add(quartzPlugin);
+		//实体类与数据库映射关系
+		arp.addMapping("t_admin", Admin.class);
+		arp.addMapping("t_log", Log.class);
+		arp.addMapping("t_user","openid", User.class);
+		//统计数据库
+		arp.addMapping("t_scanrecord","qrcode_id", ScanRecord.class);
+		arp.addMapping("t_summary", Summary.class);
+		arp.addMapping("t_hbrate", HBRate.class);
+		arp.addMapping("t_record", Record.class);
+		arp.addMapping("t_qcode_hb_config", AreaHbConfig.class);
+		arp.addMapping("t_qcode_hb_config_rate", AreaHbConfigRate.class);
+		arp.addMapping("t_master", Master.class);
+		arp.addMapping("t_res", Res.class);
+		arp.setShowSql(false);
+		arp.setDevMode(false);
+//		arp1.setShowSql(false);
+//		arp1.setDevMode(true);
+	}
+
+	@Override
+	public void configRoute(Routes me) {
+		me.add("/",AuthController.class);
+//		me.add("/qrCodeAdd", QrcodeAddController.class);
+//		me.add("/log",OperatingController.class);
+//		me.add("/index", SummaryController.class);
+//		me.add("/statistics", StatisticController.class);
+//		me.add("/hbrate", HBRateController.class);
+//		me.add("/search", SearchController.class);
+//		me.add("/tjsearch", com.qlm.controller.SearchController.class);
+//		me.add("/record", RecordController.class);
+//		me.add("/areaHb",AreaHbConfigController.class);
+//		me.add("/unpay",UnPayInfoController.class);
+//		me.add("/p",TypeController.class);
+//		me.add("/config",ConfigController.class);
+//		me.add("/role",RoleController.class,"role");
+//		me.add("/res", ResController.class,"res");
+//		me.add("/user",UserController.class);
+//		me.add("/retail",RetailPjController.class);
+//		me.add("/ywy",YwyPjController.class);
+//		me.add("/feedback",FeedBackController.class);
+//		me.add("/produce",ProduceController.class);
+//		me.add("/area",AreaController.class);
+//		me.add("/shiwu",ShiwuController.class);
+//		me.add("/jxs",JxsController.class);
+//		me.add("/hexiao",HexiaoController.class);
+//		me.add("/first",FirstZhongController.class);
+		scanClass(me);
+	}
+
+	
+	@Override
+	public void afterJFinalStart() {
+		// TODO Auto-generated method stub
+		super.afterJFinalStart();
+		com.qlm.log.Log.info("启动成功");
+	}
+
+	private void scanClass(Routes me) {
+		List<Class<?>> classListByAnnotation = ClassUtil.getClassListByAnnotation("com.qlm.admin", RequestUrl.class);
+		List<Class<?>> list = ClassUtil.getClassListByAnnotation("com.qlm.controller", RequestUrl.class);
+		classListByAnnotation.addAll(list);
+		for (Class<?> class1 : classListByAnnotation) {
+			RequestUrl annotation = class1.getAnnotation(RequestUrl.class);
+			String value = annotation.value();
+			me.add(value,(Class<? extends Controller>)class1);
+		}
+	}
+
+}

+ 621 - 0
src/main/java/com/qlm/job/AddUpJob.java

@@ -0,0 +1,621 @@
+package com.qlm.job;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.DayHbEntity;
+import com.qlm.entity.HbEntity;
+import com.qlm.entity.ScanHbEntity;
+import com.qlm.tools.LocalDateUtils;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author nommpp
+ * 汇总每天的扫码量和红包发放金额
+ */
+public class AddUpJob implements Job {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(AddUpJob.class);
+
+    private static final String T_SCAN_HB = "t_scan_hb";
+
+    private static final String T_DAY_HB = "t_day_hb";
+
+    private static final String T_DAY_HB_DETAIL = "t_day_hb_detail";
+
+    private static final String T_DAY_SCAN_HB = "t_day_scan_hb";
+
+    private static final int SINGLE_COUNT = 100000;
+
+    private static final String SPLIT = ",";
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime yestoday = now.minusDays(1);
+        String yesStart = LocalDateUtils.localToStr(LocalDateUtils.getDayStart(yestoday));
+        String yesEnd = LocalDateUtils.localToStr(LocalDateUtils.getDayEnd(yestoday));
+
+        String day = LocalDateUtils.localToDateStr(yestoday);
+
+        LOGGER.info("{} ---定时统计---",yesStart);
+
+        //查询扫码量
+        String scanCountSql = "select count(*) from t_scanrecord where scan_time >= '"+yesStart+"' and scan_time <= '"+yesEnd+"'";
+        Long scanCountDb = Db.queryLong(scanCountSql);
+        int scanCount = scanCountDb == null ? 0 : scanCountDb.intValue();
+
+        //查询发放成功的红包总个数
+        String hbCountSql = "select count(*) from t_scanrecord where send_time >= '"+yesStart+"' and send_time <= '"+yesEnd+"'";
+        Long hbCountDb = Db.queryLong(hbCountSql);
+        int hbCount = hbCountDb == null ? 0 : hbCountDb.intValue();
+
+        statisticsScanHb(yesStart,yesEnd,day,scanCount,hbCount);
+        statisticsDayScanHb(yesStart,yesEnd,day,scanCount,hbCount);
+        statisticsDayScanHbDetail(yesStart,yesEnd,day,hbCount);
+
+        LOGGER.info("{} 定时统计完成",yesStart);
+    }
+
+    /**
+     * 统计总的扫码量和发放成功的红包金额
+     * @param startTime 统计开始时间
+     * @param endTime 统计结束时间
+     * @param day 时间的yyyy-MM-dd表示
+     */
+    private void statisticsScanHb(String startTime,String endTime,String day,int scanCount,int hbTotalCount){
+        LOGGER.info("{} 号 开始统计 {} 表数据",day, T_SCAN_HB);
+
+        if(hbTotalCount > SINGLE_COUNT){
+            //总次数
+            int count = hbTotalCount / SINGLE_COUNT;
+            //剩余次数
+            int residue = hbTotalCount % SINGLE_COUNT;
+            int hbAmount = 0;
+            int len = 0;
+            for (int i = 0; i < count; i++) {
+                String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='" + startTime + "' and send_time<='" + endTime + "' limit " + len + "," + SINGLE_COUNT + "";
+                List<Record> listHb = Db.find(sqlHb);
+                hbAmount += listHb.parallelStream().mapToInt(r->r.getInt("amount")).sum();
+                len += SINGLE_COUNT;
+            }
+
+            if(residue > 0){
+                String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+ hbTotalCount +"";
+                List<Record> listHb = Db.find(sqlHb);
+                hbAmount += listHb.parallelStream().mapToInt(r->r.getInt("amount")).sum();
+            }
+            Record record = new Record();
+            record.set("day_",day);
+            record.set("scan_", scanCount);
+            record.set("hb_", hbAmount);
+            Db.save(T_SCAN_HB,record);
+        }else{
+            //查询红包发放金额
+            String hbSql = "select sum(amount) from t_scanrecord where send_time >= '"+startTime+"' and send_time <= '"+endTime+"'";
+            BigDecimal hbCountDb = Db.queryBigDecimal(hbSql);
+            int hbCount = hbCountDb == null ? 0 : hbCountDb.intValue();
+            Record record = new Record();
+            record.set("day_",day);
+            record.set("scan_", scanCount);
+            record.set("hb_", hbCount);
+            Db.save(T_SCAN_HB,record);
+        }
+        LOGGER.info("{} 号 {} 表数据 统计完成", day,T_SCAN_HB);
+    }
+
+
+    /**
+     * 获得扫码map
+     * @param startTime 统计开始日期
+     * @param endTime 统计结束日期
+     * @param day yyyy-MM-dd表示
+     * @param scanCount 总扫码次数
+     * @return Map<String,Integer>
+     */
+    private Map<String,Integer> getScanMap(String startTime,String endTime,String day,int scanCount){
+        Map<String,Integer> scanMap = new HashMap<>();
+        //总次数
+        int count = scanCount / SINGLE_COUNT;
+        //剩余次数
+        int residue = scanCount % SINGLE_COUNT;
+        int len = 0;
+        for (int i = 0; i < count; i++) {
+            String sqlScan = "select scan_time,type_,area from t_scanrecord where scan_time >='"+startTime+"' and scan_time <= '"+endTime+"' limit "+len+","+ SINGLE_COUNT +"";
+            List<Record> listScan = Db.find(sqlScan);
+            //统计扫码量
+            Map<Integer,List<Record>> typeMap = listScan.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+            for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
+                List<Record> areaList = typeEntry.getValue();
+                if(!areaList.isEmpty()){
+                    Map<String,List<Record>> areaMap = areaList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+                    for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+
+                        List<Record> resultList = areaEntry.getValue();
+                        Integer scan = resultList.size();
+                        //拼接key day_ + type_ + area_
+                        String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
+                        if(scanMap.get(key) == null){
+                            scanMap.put(key,scan);
+                        }else{
+                            Integer oldScan = scanMap.get(key);
+                            scanMap.put(key,oldScan+scan);
+                        }
+                    }
+                }
+            }
+            len += SINGLE_COUNT;
+        }
+
+        if(residue > 0){
+            String sqlScan = "select scan_time,type_,area from t_scanrecord where scan_time >='"+startTime+"' and scan_time <= '"+endTime+"' limit "+len+","+ scanCount +"";
+            List<Record> listScan = Db.find(sqlScan);
+            //统计扫码量
+            Map<Integer,List<Record>> typeMap = listScan.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+            for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
+                List<Record> areaList = typeEntry.getValue();
+                if(!areaList.isEmpty()){
+                    Map<String,List<Record>> areaMap = areaList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+                    for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+
+                        List<Record> resultList = areaEntry.getValue();
+                        Integer scan = resultList.size();
+                        //拼接key day_ + type_ + area_
+                        String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
+                        if(scanMap.get(key) == null){
+                            scanMap.put(key,scan);
+                        }else{
+                            Integer oldScan = scanMap.get(key);
+                            scanMap.put(key,oldScan+scan);
+                        }
+                    }
+                }
+            }
+        }
+
+        return scanMap;
+    }
+
+    /**
+     * 获得hbmap
+     * @param startTime 统计开始时间
+     * @param endTime 统计结束时间
+     * @param day yyyy-MM-dd表示
+     * @param hbCount 总红包发放个数
+     * @return Map<String, HbEntity>
+     */
+    private Map<String, HbEntity> getHbMap(String startTime, String endTime, String day, int hbCount){
+        Map<String,HbEntity> hbMap = new HashMap<>();
+        //总次数
+        int count = hbCount / SINGLE_COUNT;
+        //剩余次数
+        int residue = hbCount % SINGLE_COUNT;
+
+        int len = 0;
+        for (int i = 0; i < count; i++) {
+            String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+ SINGLE_COUNT +"";
+            List<Record> listHb = Db.find(sqlHb);
+            //统计红包和个数
+            //对map里的list再根据 type 进行分组
+            Map<Integer,List<Record>> typeHbMap = listHb.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+            for(Map.Entry<Integer,List<Record>> typeEntry:typeHbMap.entrySet()){
+                List<Record> areaList = typeEntry.getValue();
+                if(!areaList.isEmpty()){
+                    Map<String,List<Record>> areaMap = areaList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+                    for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                        HbEntity hbEntity = new HbEntity();
+                        List<Record> resultList = areaEntry.getValue();
+                        int hb = resultList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
+                        long subHbCount = resultList.parallelStream().count();
+                        hbEntity.setHbAmount(hb);
+                        hbEntity.setHbCount((int) subHbCount);
+
+                        String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
+
+                        if(hbMap.get(key) == null){
+                            hbMap.put(key,hbEntity);
+                        }else{
+                            HbEntity oldHbEntity = hbMap.get(key);
+                            HbEntity newHbEntity = new HbEntity();
+                            newHbEntity.setHbAmount(oldHbEntity.getHbAmount()+hbEntity.getHbAmount());
+                            newHbEntity.setHbCount(oldHbEntity.getHbCount()+hbEntity.getHbCount());
+                            hbMap.put(key,newHbEntity);
+                        }
+                    }
+                }
+            }
+            len += SINGLE_COUNT;
+        }
+
+        if(residue > 0){
+            String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+ hbCount +"";
+            List<Record> listHb = Db.find(sqlHb);
+            //统计红包和个数
+            //对map里的list再根据 type 进行分组
+            Map<Integer,List<Record>> typeHbMap = listHb.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+            for(Map.Entry<Integer,List<Record>> typeEntry:typeHbMap.entrySet()){
+                List<Record> areaList = typeEntry.getValue();
+                if(!areaList.isEmpty()){
+                    Map<String,List<Record>> areaMap = areaList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+                    for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                        HbEntity hbEntity = new HbEntity();
+                        List<Record> resultList = areaEntry.getValue();
+                        int hb = resultList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
+                        long subHbCount = resultList.parallelStream().count();
+                        hbEntity.setHbAmount(hb);
+                        hbEntity.setHbCount((int) subHbCount);
+
+                        String key = day+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
+
+                        if(hbMap.get(key) == null){
+                            hbMap.put(key,hbEntity);
+                        }else{
+                            HbEntity oldHbEntity = hbMap.get(key);
+                            HbEntity newHbEntity = new HbEntity();
+                            newHbEntity.setHbAmount(oldHbEntity.getHbAmount()+hbEntity.getHbAmount());
+                            newHbEntity.setHbCount(oldHbEntity.getHbCount()+hbEntity.getHbCount());
+                            hbMap.put(key,newHbEntity);
+                        }
+                    }
+                }
+            }
+        }
+
+        return hbMap;
+    }
+
+
+    /**
+     * 根据品相和区域分组统计扫码量,红包发放个数和红包发放金额
+     * @param startTime 统计开始时间
+     * @param endTime 统计结束时间
+     * @param day 时间的yyyy-MM-dd表示
+     * @param scanCount 总的扫码量
+     * @param hbCount 发放成功的红包数量
+     */
+    private void statisticsDayScanHb(String startTime,String endTime,String day,int scanCount,int hbCount) {
+        LOGGER.info("{} 号 开始统计 {} 表数据",day, T_DAY_SCAN_HB);
+
+        if(scanCount > SINGLE_COUNT) {
+            Map<String, ScanHbEntity> scanHbMap = new HashMap<>();
+            Map<String, Integer> scanMap = getScanMap(startTime, endTime, day, scanCount);
+
+            Map<String,HbEntity> hbMap = getHbMap(startTime,endTime,day,hbCount);
+
+            for(Map.Entry<String,Integer> scanEntry:scanMap.entrySet()){
+                ScanHbEntity scanHbEntity = new ScanHbEntity();
+                scanHbEntity.setScanCount(scanEntry.getValue());
+                scanHbMap.put(scanEntry.getKey(),scanHbEntity);
+            }
+
+            for(Map.Entry<String,HbEntity> hbEntity:hbMap.entrySet()){
+                if(scanHbMap.get(hbEntity.getKey()) != null){
+                    ScanHbEntity scanHbEntity = scanHbMap.get(hbEntity.getKey());
+                    scanHbEntity.setHbAmount(hbEntity.getValue().getHbAmount());
+                    scanHbEntity.setHbCount(hbEntity.getValue().getHbCount());
+                }
+            }
+
+            for(Map.Entry<String,ScanHbEntity> scanHbEntry:scanHbMap.entrySet()){
+                Record record = new Record();
+                String[] dta = scanHbEntry.getKey().split(SPLIT);
+                record.set("day_",dta[0]);
+                record.set("type_",dta[1]);
+                record.set("area_",dta[2]);
+                record.set("scan_",scanHbEntry.getValue().getScanCount());
+                record.set("hb_",scanHbEntry.getValue().getHbAmount());
+                record.set("hbc_",scanHbEntry.getValue().getHbCount());
+                Db.save(T_DAY_SCAN_HB,record);
+            }
+
+        }else{
+            String sqlScan = "select scan_time,type_,area from t_scanrecord where scan_time >='"+startTime+"' and scan_time<='"+endTime+"'";
+            List<Record> listScan = Db.find(sqlScan);
+            //统计扫码量
+            Map<Integer,List<Record>> typeMap = listScan.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+            for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
+                List<Record> areaList = typeEntry.getValue();
+                if(!areaList.isEmpty()){
+                    Map<String,List<Record>> areaMap = areaList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+                    for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                        Record typeRecord = new Record();
+                        typeRecord.set("day_",day);
+                        typeRecord.set("type_",typeEntry.getKey());
+                        typeRecord.set("area_",areaEntry.getKey());
+
+                        List<Record> resultList = areaEntry.getValue();
+                        Integer scan = resultList.size();
+                        typeRecord.set("scan_",scan);
+
+                        Db.save(T_DAY_SCAN_HB,typeRecord);
+                    }
+                }
+            }
+
+            String sqlHb = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"'";
+            List<Record> listHb = Db.find(sqlHb);
+            //统计红包和个数
+            //对map里的list再根据 type 进行分组
+            Map<Integer,List<Record>> typeHbMap = listHb.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+            String sql = "select * from "+ T_DAY_SCAN_HB +" where day_ = ? and type_ = ? and area_ = ? limit 1";
+
+            for(Map.Entry<Integer,List<Record>> typeEntry:typeHbMap.entrySet()){
+                List<Record> areaList = typeEntry.getValue();
+                if(!areaList.isEmpty()){
+                    Map<String,List<Record>> areaMap = areaList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+                    for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                        Record typeRecord = Db.findFirst(sql,day,typeEntry.getKey(),areaEntry.getKey());
+                        if(typeRecord == null){
+                            continue;
+                        }
+                        List<Record> resultList = areaEntry.getValue();
+                        int hb = resultList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
+                        long count = resultList.parallelStream()
+                                .count();
+                        typeRecord.set("hb_",hb);
+                        typeRecord.set("hbc_", (int) count);
+                        Db.update(T_DAY_SCAN_HB,typeRecord);
+                    }
+                }
+            }
+
+        }
+        LOGGER.info("{} 号 {} 表数据 统计完成",day,T_DAY_SCAN_HB);
+    }
+
+    /**
+     * 统计每种红包金额的发放个数和发放的金额
+     * 并统计每种红包金额在不同品相和区域发放的个数和发放的金额
+     * @param startTime 统计开始时间
+     * @param endTime 统计结束时间
+     * @param day 时间的yyyy-MM-dd表示
+     * @param hbCount 发放成功的红包数量
+     */
+    private void statisticsDayScanHbDetail(String startTime,String endTime,String day,int hbCount){
+        LOGGER.info("{} 号 开始统计 {}表 和 {} 表数据",day,T_DAY_HB,T_DAY_HB_DETAIL);
+
+        if(hbCount > SINGLE_COUNT){
+            int count = hbCount / SINGLE_COUNT;
+            int residue = hbCount % SINGLE_COUNT;
+            int len = 0;
+            Map<String, DayHbEntity> dayHbMap = new HashMap<>();
+            Map<String,DayHbEntity> dayHbDetailMap = new HashMap<>();
+            for (int i = 0; i < count; i++) {
+                String sql = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+SINGLE_COUNT+"";
+                List<Record> listHb = Db.find(sql);
+
+                Map<Integer,List<Record>> amountMap = listHb.parallelStream()
+                        .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
+                TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(amountMap);
+
+                //给map按照key排序
+                List<Map.Entry<Integer,List<Record>>> amountKeyList = new ArrayList<>(amtTreeMap.entrySet());
+                amountKeyList.sort(Comparator.comparing(Map.Entry::getKey));
+
+                for(Map.Entry<Integer,List<Record>> amountEntry:amtTreeMap.entrySet()){
+                    List<Record> amountList = amountEntry.getValue();
+                    if(!amountList.isEmpty()){
+                        String dayHbKey = day +SPLIT+amountEntry.getKey();
+                        if(dayHbMap.get(dayHbKey) == null){
+                            DayHbEntity dayHbEntity = new DayHbEntity();
+                            dayHbEntity.setHb(amountEntry.getKey());
+                            dayHbEntity.setHbCount(amountList.size());
+                            dayHbMap.put(dayHbKey,dayHbEntity);
+                        }else{
+                            DayHbEntity oldDayHbEntity = dayHbMap.get(dayHbKey);
+                            DayHbEntity newDayHbEntity = new DayHbEntity();
+                            newDayHbEntity.setHb(oldDayHbEntity.getHb());
+                            newDayHbEntity.setHbCount(oldDayHbEntity.getHbCount()+amountList.size());
+                            dayHbMap.put(dayHbKey,newDayHbEntity);
+                        }
+
+                        Map<Integer,List<Record>> typeMap = amountList.parallelStream()
+                                .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+                        for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
+                            List<Record> typeList = typeEntry.getValue();
+                            if(!typeList.isEmpty()){
+                                Map<String,List<Record>> areaMap = typeList.parallelStream()
+                                        .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+
+                                for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                                    List<Record> areaList = areaEntry.getValue();
+                                    if(!areaList.isEmpty()){
+
+                                        //Integer hbt = areaList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
+                                        long hbc = areaList.parallelStream().count();
+                                        String key = day +SPLIT+amountEntry.getKey()+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
+                                        if(dayHbDetailMap.get(key) == null){
+                                            DayHbEntity dayHbEntity = new DayHbEntity();
+                                            dayHbEntity.setHb(amountEntry.getKey());
+                                            dayHbEntity.setHbCount((int) hbc);
+                                            dayHbDetailMap.put(key,dayHbEntity);
+                                        }else{
+                                            DayHbEntity oldDayHbEntity = dayHbDetailMap.get(key);
+                                            DayHbEntity newDayHbEntity = new DayHbEntity();
+                                            newDayHbEntity.setHb(oldDayHbEntity.getHb());
+                                            newDayHbEntity.setHbCount((int) (oldDayHbEntity.getHbCount()+hbc));
+                                            dayHbDetailMap.put(key,newDayHbEntity);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+
+                    }
+                }
+                len += SINGLE_COUNT;
+            }
+
+            if(residue > 0){
+                String sql = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"' limit "+len+","+hbCount+"";
+                List<Record> listHb = Db.find(sql);
+                Map<Integer,List<Record>> amountMap = listHb.parallelStream()
+                        .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
+                TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(amountMap);
+
+                //给map按照key排序
+                List<Map.Entry<Integer,List<Record>>> amountKeyList = new ArrayList<>(amtTreeMap.entrySet());
+                amountKeyList.sort(Comparator.comparing(Map.Entry::getKey));
+
+                for(Map.Entry<Integer,List<Record>> amountEntry:amtTreeMap.entrySet()){
+                    List<Record> amountList = amountEntry.getValue();
+                    if(!amountList.isEmpty()){
+                        String dayHbKey = day +SPLIT+amountEntry.getKey();
+                        if(dayHbMap.get(dayHbKey) == null){
+                            DayHbEntity dayHbEntity = new DayHbEntity();
+                            dayHbEntity.setHb(amountEntry.getKey());
+                            dayHbEntity.setHbCount(amountList.size());
+                            dayHbMap.put(dayHbKey,dayHbEntity);
+                        }else{
+                            DayHbEntity oldDayHbEntity = dayHbMap.get(dayHbKey);
+                            DayHbEntity newDayHbEntity = new DayHbEntity();
+                            newDayHbEntity.setHb(oldDayHbEntity.getHb());
+                            newDayHbEntity.setHbCount(oldDayHbEntity.getHbCount()+amountList.size());
+                            dayHbMap.put(dayHbKey,newDayHbEntity);
+                        }
+
+                        Map<Integer,List<Record>> typeMap = amountList.parallelStream()
+                                .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+                        for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
+                            List<Record> typeList = typeEntry.getValue();
+                            if(!typeList.isEmpty()){
+                                Map<String,List<Record>> areaMap = typeList.parallelStream()
+                                        .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+
+                                for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                                    List<Record> areaList = areaEntry.getValue();
+                                    if(!areaList.isEmpty()){
+
+                                        //Integer hbt = areaList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
+                                        long hbc = areaList.parallelStream().count();
+                                        String key = day +SPLIT+amountEntry.getKey()+SPLIT+typeEntry.getKey()+SPLIT+areaEntry.getKey();
+                                        if(dayHbDetailMap.get(key) == null){
+                                            DayHbEntity dayHbEntity = new DayHbEntity();
+                                            dayHbEntity.setHb(amountEntry.getKey());
+                                            dayHbEntity.setHbCount((int) hbc);
+                                            dayHbDetailMap.put(key,dayHbEntity);
+                                        }else{
+                                            DayHbEntity oldDayHbEntity = dayHbDetailMap.get(key);
+                                            DayHbEntity newDayHbEntity = new DayHbEntity();
+                                            newDayHbEntity.setHb(oldDayHbEntity.getHb());
+                                            newDayHbEntity.setHbCount((int) (oldDayHbEntity.getHbCount()+hbc));
+                                            dayHbDetailMap.put(key,newDayHbEntity);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+
+                    }
+                }
+            }
+
+            for(Map.Entry<String,DayHbEntity> dayHbEntry:dayHbMap.entrySet()){
+                Record amountRecord = new Record();
+                amountRecord.set("day_",day);
+                amountRecord.set("hb_",dayHbEntry.getValue().getHb());
+                amountRecord.set("hbc_",dayHbEntry.getValue().getHbCount());
+                amountRecord.set("hbt_",dayHbEntry.getValue().getHbAmount());
+                Db.save(T_DAY_HB,amountRecord);
+            }
+
+            for(Map.Entry<String,DayHbEntity> dayHbDetailEntry:dayHbDetailMap.entrySet()){
+                Record typeRecord = new Record();
+                String[] dta = dayHbDetailEntry.getKey().split(SPLIT);
+                typeRecord.set("hb_",dayHbDetailEntry.getValue().getHb());
+                typeRecord.set("day_",day);
+                typeRecord.set("type_",dta[2]);
+                typeRecord.set("area_",dta[3]);
+                typeRecord.set("hbc_",dayHbDetailEntry.getValue().getHbCount());
+                typeRecord.set("hbt_",dayHbDetailEntry.getValue().getHbAmount());
+                Db.save(T_DAY_HB_DETAIL,typeRecord);
+            }
+
+        }else{
+            String sql = "select send_time,amount,type_,area from t_scanrecord where send_time >='"+startTime+"' and send_time<='"+endTime+"'";
+            List<Record> listHb = Db.find(sql);
+            //需要过滤掉未发送成功的
+            Map<Integer,List<Record>> amountMap = listHb.parallelStream()
+                    .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
+
+            TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(amountMap);
+
+            //给map按照key排序
+            List<Map.Entry<Integer,List<Record>>> amountKeyList = new ArrayList<>(amtTreeMap.entrySet());
+            amountKeyList.sort(Comparator.comparing(Map.Entry::getKey));
+
+            for(Map.Entry<Integer,List<Record>> amountEntry:amtTreeMap.entrySet()){
+                List<Record> amountList = amountEntry.getValue();
+                if(!amountList.isEmpty()){
+                    Record amountRecord = new Record();
+                    amountRecord.set("day_",day);
+                    amountRecord.set("hb_",amountEntry.getKey());
+                    amountRecord.set("hbc_",amountList.size());
+                    amountRecord.set("hbt_",amountEntry.getKey()*amountList.size());
+                    Db.save(T_DAY_HB,amountRecord);
+
+                    Map<Integer,List<Record>> typeMap = amountList.parallelStream()
+                            .collect(Collectors.groupingBy(r->r.getInt("type_"),Collectors.toList()));
+
+                    for(Map.Entry<Integer,List<Record>> typeEntry:typeMap.entrySet()){
+                        List<Record> typeList = typeEntry.getValue();
+                        if(!typeList.isEmpty()){
+                            Map<String,List<Record>> areaMap = typeList.parallelStream()
+                                    .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.toList()));
+
+                            for(Map.Entry<String,List<Record>> areaEntry:areaMap.entrySet()){
+                                List<Record> areaList = areaEntry.getValue();
+                                if(!areaList.isEmpty()){
+                                    Record typeRecord = new Record();
+                                    typeRecord.set("hb_",amountEntry.getKey());
+                                    typeRecord.set("day_",day);
+                                    typeRecord.set("type_",typeEntry.getKey());
+                                    typeRecord.set("area_",areaEntry.getKey());
+
+                                    Integer hbt = areaList.parallelStream().mapToInt(r -> r.getInt("amount")).sum();
+                                    long hbc = areaList.parallelStream()
+                                            .count();
+                                    typeRecord.set("hbc_", (int) hbc);
+                                    typeRecord.set("hbt_",hbt);
+
+                                    Db.save(T_DAY_HB_DETAIL,typeRecord);
+
+                                }
+                            }
+                        }
+                    }
+
+                }
+            }
+        }
+        LOGGER.info("{} 号 {} 和 {} 表数据 统计完成",day,T_DAY_HB,T_DAY_HB_DETAIL);
+    }
+}

+ 88 - 0
src/main/java/com/qlm/job/CheckYuEJob.java

@@ -0,0 +1,88 @@
+package com.qlm.job;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import com.jfinal.kit.HttpKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.tools.WxUtil;
+
+public class CheckYuEJob implements Job{
+
+	static boolean running =false;
+	@Override
+	public void execute(JobExecutionContext context)
+			throws JobExecutionException {
+		if(running){
+			return;
+		}
+		running = true;
+		try{
+			checkAmount();
+		}finally{
+			running = false;
+		}
+		
+	}
+	static Record lstRecord = null;
+	private void checkAmount() {
+		Date date = new Date();
+		Calendar instance = Calendar.getInstance();
+		int hour = instance.get(Calendar.HOUR_OF_DAY);
+		if(hour>=1 && hour<7){
+			return;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
+		String format = sdf.format(date);
+		Record findFirst = Db.findFirst("select * from t_pay_amount where date_ = ?",format);
+		int amount = WxUtil.getInt("amount_", findFirst);
+		if(lstRecord == null){
+			lstRecord = new Record();
+			lstRecord.set("create_time", new Date())
+			.set("amount", amount);
+		}else{
+			int lasteramount = JFinalUtil.getInt("amount", lstRecord);
+			Date lstRunDate = lstRecord.getDate("send_time");
+			long lstLong = 0;
+			if(lstRunDate != null){
+				lstLong = lstRunDate.getTime();
+			}
+			long cur = System.currentTimeMillis();
+			long jiange = 1000 * 60* 5;
+			boolean sendMail = false;
+			if(amount==lasteramount){
+				if((cur-lstLong)>=jiange){
+					sendMail = true;
+				}
+			}
+			
+			if(sendMail){
+				sendEmail("41405217@qq.com", "胖哥异常");
+				lstRecord.set("send_time",new Date());
+			}
+			lstRecord.set("amount", amount).set("create_time", new Date());
+			
+		}
+
+	}
+	
+	public static void sendEmail(String address,String text){
+		String encode2;
+		try {
+			encode2 = URLEncoder.encode(text,"utf-8");
+			String string = HttpKit.get("http://10.24.242.248:81/huangye3/e/sendEmail?text="+encode2+"&address=41405217@qq.com", null);
+		} catch (UnsupportedEncodingException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+}

+ 426 - 0
src/main/java/com/qlm/job/MoveData.java

@@ -0,0 +1,426 @@
+package com.qlm.job;
+
+import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.druid.DruidPlugin;
+import com.jfinal.weixin.sdk.kit.PaymentKit;
+import com.qlm.tools.LocalDateUtils;
+import com.qlm.tools.StateMentsUtils;
+import com.qlm.tools.WxUtil;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author nommpp
+ * 每天10点开始
+ */
+public class MoveData implements Job {
+    protected final static Logger log = LoggerFactory.getLogger(MoveData.class);
+    private static final int SINGLE_C = 100000;
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) {
+		Calendar instance = Calendar.getInstance();
+		int hour = instance.get(Calendar.HOUR_OF_DAY);
+		instance.add(Calendar.DAY_OF_MONTH, -1);
+		Date time = instance.getTime();
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
+		String format = sdf.format(time);
+		try {
+			if(hour>=9 && hour<=12){
+				MoveData.checkNo(format);
+			}
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+    }
+    private static void con(){
+		DruidPlugin dp = new DruidPlugin("jdbc:mysql://rm-bp1j1ibp4ra74p110to.mysql.rds.aliyuncs.com:3306/kongka?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull", "dnzc", "Wangzih2022+-");
+		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
+		// ��web����Ψһ�IJ�ͬ��Ҫ�ֶ�����һ����ز����start()����
+		dp.start();
+		arp.start();
+	}
+    public static void main(String[] args) throws Exception {
+		con();
+		String date = "2022.06.26";
+		checkNo(date);
+	}
+	public static void checkNo(String date) throws Exception {
+		log.info("开始检查单号:"+date);
+		String startTime = date+" 00:00:00";
+         String endTime =  date+" 23:59:59";
+         readNo(date);
+		String payCountSql = "select count(*) from t_order2 where pay_time >= '"+startTime+"' and pay_time <= '"+endTime+"' and amount <=100000";
+        Long payCountDb = Db.queryLong(payCountSql);
+        if(payCountDb == null){
+        	payCountDb = 0l;
+        }
+        if(payCountDb == 0){
+        	log.info("暂无资金");
+        	return;
+        }
+        Long scanCount = Db.queryLong("select count(*) from t_scanrecord where send_time >='"+startTime+"' and send_time <='"+endTime+"'");
+        if(scanCount == null){
+        	scanCount = 0l;
+        }
+        if(!scanCount .equals(payCountDb)){
+        	Map<String,Record> maps = new HashMap<String, Record>();
+        	List<Record> find = Db.find("select * from t_order2 where pay_time >= '"+startTime+"' and pay_time <= '"+endTime + "' and amount <=100000");
+        	for (Record record : find) {
+        		String wx_no = record.getStr("wx_no");
+        		maps.put(wx_no, record);
+			}
+            List<Record> list = Db.find("select * from t_scanrecord where send_time >='"+startTime+"' and send_time <='"+endTime+"'");
+            for (Record record : list) {
+            	String weixin_no_ = record.getStr("weixin_no_");
+            	maps.remove(weixin_no_);
+			}
+            Set<String> keySet = maps.keySet();
+            for (String nos : keySet) {
+            	Record record = maps.get(nos);
+            	String pay_no = record.getStr("pay_no");
+            	Record findFirst = Db.findFirst("select * from t_qcode_hb_a where no_ = ?",pay_no);
+            	if(findFirst != null){
+            		String id = findFirst.getStr("id");
+            		Date payDate = record.getDate("pay_time");
+            		findFirst.set("send_time",payDate).set("send_state", 1);
+            		Db.update("t_qcode_hb_a", findFirst);
+            		Record findById = Db.findById("t_scanrecord", "qrcode_id", id);
+            		if(findById != null){
+            			findById.set("send_time",payDate).set("send_state", 1).set("weixin_no_", nos);
+            			Db.update("t_scanrecord", "qrcode_id", findById);
+            		}
+            		log.info(id+" 更新完成");
+            	}
+            	
+			}
+        }
+        log.info(date+" 完成");
+	}
+
+    /**
+     * 核对数据
+     */
+    private static void check(String startTime,String endTime) {
+        log.info("{}开始核对数据",startTime);
+
+        ExecutorService executors = Executors.newFixedThreadPool(4);
+
+        CompletableFuture<List<String>> c1 = CompletableFuture.supplyAsync(()->{
+            log.info("开始查询 {} 表数据","t_order2");
+            String payCountSql = "select count(*) from t_order2 where pay_time >= '"+startTime+"' and pay_time <= '"+endTime+"'";
+            Long payCountDb = Db.queryLong(payCountSql);
+            int payCount = payCountDb == null ? 0 : payCountDb.intValue();
+            if(payCount > SINGLE_C){
+                //总次数
+                int count = payCount / SINGLE_C;
+                //剩余次数
+                int residue = payCount % SINGLE_C;
+                List<String> ls1 = new ArrayList<>();
+                int len = 0;
+                for (int i = 0; i < count; i++) {
+                    String sqlPay = "select wx_no from t_order2 where pay_time >='" + startTime + "' and pay_time<='" + endTime + "' limit " + len + "," + SINGLE_C + "";
+                    List<Record> payList = Db.find(sqlPay);
+                    for (Record record : payList) {
+                        ls1.add(record.getStr("wx_no"));
+                    }
+                    len += SINGLE_C;
+                }
+
+                if(residue > 0){
+                    String sqlPay = "select wx_no from t_order2 where pay_time >='" + startTime + "' and pay_time<='" + endTime + "' limit " + len + "," + payCount + "";
+                    List<Record> payList = Db.find(sqlPay);
+                    for (Record record : payList) {
+                        ls1.add(record.getStr("wx_no"));
+                    }
+                }
+                log.info("{} 表数据查询完成","t_order2");
+                return ls1;
+            }else{
+                String sql1 = "select wx_no from t_order2 where pay_time >='"+startTime+"' and pay_time <='"+endTime+"'";
+                return Db.query(sql1);
+            }
+
+        },executors);
+
+        CompletableFuture<List<String>> c2 = CompletableFuture.supplyAsync(()->{
+            //查询发放成功的红包总个数
+            log.info("开始查询 {} 表数据","t_scanrecord");
+            String hbCountSql = "select count(*) from t_scanrecord where send_time >= '"+startTime+"' and send_time <= '"+endTime+"'";
+            Long hbCountDb = Db.queryLong(hbCountSql);
+            int hbCount = hbCountDb == null ? 0 : hbCountDb.intValue();
+            if(hbCount > SINGLE_C){
+                //总次数
+                int count = hbCount / SINGLE_C;
+                //剩余次数
+                int residue = hbCount % SINGLE_C;
+                List<String> ls2 = new ArrayList<>();
+                int len = 0;
+                for (int i = 0; i < count; i++) {
+                    String sqlHb = "select weixin_no_ from t_scanrecord where send_time >='" + startTime + "' and send_time<='" + endTime + "' limit " + len + "," + SINGLE_C + "";
+                    List<Record> hbList = Db.find(sqlHb);
+                    for (Record record : hbList) {
+                        ls2.add(record.getStr("weixin_no_"));
+                    }
+                    len += SINGLE_C;
+                }
+
+                if(residue > 0){
+                    String sqlHb = "select weixin_no_ from t_scanrecord where send_time >='" + startTime + "' and send_time<='" + endTime + "' limit " + len + "," + hbCount + "";
+                    List<Record> hbList = Db.find(sqlHb);
+                    for (Record record : hbList) {
+                        ls2.add(record.getStr("weixin_no_"));
+                    }
+                }
+                log.info("{} 表数据查询完成","t_scanrecord");
+                return ls2;
+            }else{
+                String sql2 = "select weixin_no_ from t_scanrecord where send_time >='"+startTime+"' and send_time <='"+endTime+"'";
+                return Db.query(sql2);
+            }
+        },executors);
+
+        c1.thenCombine(c2, MoveData::getDiffent).thenApplyAsync((lst3) -> {
+            if (lst3.isEmpty()) {
+                log.info("{} 数据准确,无需核对", startTime);
+                return null;
+            }
+            List<Record> records = new ArrayList<>(lst3.size());
+            lst3.parallelStream().forEach(key -> {
+                Record record = Db.findFirst("select * from t_order2 where wx_no = ?", key);
+                if (record != null) {
+                    record.set("status_", 1);
+                    Db.update("t_order2", "pay_no", record);
+                    records.add(record);
+                } else {
+                    log.info("{} 号微信对账单不存在此 wx_no:{}", startTime, key);
+                }
+            });
+            if (records.isEmpty()) {
+                log.info("{} 号微信对账单有误", startTime);
+            }
+            return records;
+        }, executors).thenApplyAsync(records -> {
+            if (records == null) {
+                return null;
+            }
+            List<Record> hbRecords = new ArrayList<>(records.size());
+            if (!records.isEmpty()) {
+                records.parallelStream().forEach(r -> {
+                    String payNo = r.getStr("pay_no");
+                    if(payNo != null && !payNo.startsWith("c")){
+                        Record unPayRecord = Db.findFirst("select * from t_unpayinfo where pay_no = ? limit 1",payNo);
+                        String code;
+                        if(unPayRecord == null || unPayRecord.getStr("id") == null){
+                            log.info("补发表没有订单号 {} 记录",payNo);
+                            /* 补发记录太多会占满cpu和内存  2020.03.12 lds
+                            String tableName = "t_qcode_hb_a";
+                            Record hbRecord = Db.findFirst("select * from t_qcode_hb_a where no_ = ? limit 1",payNo);
+                            if (hbRecord != null) {
+                                hbRecord.set("send_state", 1).set("send_time", r.getDate("pay_time"));
+                                //Db.update("update t_qcode_hb_a set send_state = ? and send_time = ? where no_ = ?",1,r.getDate("pay_time"),r.getStr("pay_no"));
+                                Db.update(tableName, hbRecord);
+                                hbRecord.set("wx_no", r.getStr("wx_no"));
+                                hbRecords.add(hbRecord);
+                            }
+                            */
+                        }else{
+                            code = unPayRecord.getStr("id");
+                            String prefix = code.substring(0,1);
+                            String tableName = "t_qcode_hb_"+prefix;
+                            Record hbRecord = Db.findById(tableName,code);
+                            if (hbRecord != null) {
+                                hbRecord.set("send_state", 1).set("send_time", r.getDate("pay_time"));
+                                //Db.update("update t_qcode_hb_a set send_state = ? and send_time = ? where no_ = ?",1,r.getDate("pay_time"),r.getStr("pay_no"));
+                                Db.update(tableName, hbRecord);
+                                hbRecord.set("wx_no", r.getStr("wx_no"));
+                                hbRecords.add(hbRecord);
+                            }
+                        }
+                    }
+                });
+                if (hbRecords.isEmpty()) {
+                    log.info("{} 红包表没有记录,不能获取二维码,无法核对", startTime);
+                }
+            }
+            return hbRecords;
+        }, executors).thenApplyAsync(hbrecords -> {
+            if (hbrecords == null) {
+                return true;
+            }
+            List<Record> scanRecords = new ArrayList<>();
+            if (!hbrecords.isEmpty()) {
+                hbrecords.parallelStream().forEach(r -> {
+                    log.info("有误差的二维码 {}", r.getStr("id"));
+                    Db.update("delete from t_unpayinfo where id = ?", r.getStr("id"));
+                    Record sr = Db.findById("t_scanrecord", "qrcode_id", r.getStr("id"));
+                    sr.set("send_state", 1).set("send_time", r.getDate("send_time")).set("weixin_no_", r.getStr("wx_no"));
+                    Db.update("t_scanrecord", "qrcode_id", sr);
+                    scanRecords.add(sr);
+                });
+                if (scanRecords.isEmpty()) {
+                    log.info("{} 扫码表没有记录,无法核对", startTime);
+                    return false;
+                }
+            }
+            return !scanRecords.isEmpty();
+        }, executors).handle((res, ex) -> {
+            if (ex != null) {
+                executors.shutdown();
+                log.info("{} 核对数据出现异常,原因 {}", startTime,ex.getMessage());
+                ex.printStackTrace();
+            } else {
+                executors.shutdown();
+                if (res) {
+                    log.info("{} 核对数据成功", startTime);
+                }else{
+                    log.info("{} 核对数据失败", startTime);
+                }
+            }
+            return res;
+        });
+    }
+
+    private static List<String> getDiffent(List<String> collmax, List<String> collmin)
+    {
+        //使用LinkeList防止差异过大时,元素拷贝
+        List<String> csReturn = new LinkedList();
+        List<String> max = collmax;
+        List<String> min = collmin;
+        //先比较大小,这样会减少后续map的if判断次数
+        if(collmax.size()<collmin.size())
+        {
+            max = collmin;
+            min = collmax;
+        }
+        //直接指定大小,防止再散列
+        Map<String,Integer> map = new HashMap<>(max.size());
+        for (String object : min) {
+            map.put(object, 1);
+        }
+        for (String object : max) {
+            if(map.get(object)==null)
+            {
+                csReturn.add(object);
+            }
+        }
+        return csReturn;
+    }
+
+    /**
+     * 从微信读取指定日期的资金账单
+     * @param date 指定的日期 yyyy.MM.dd 格式
+     * @throws Exception
+     */
+    private static void  readNo(String date) throws Exception {
+    	String startTime = date+" 00:00:00";
+        String endTime =  date+" 23:59:59";
+		String payCountSql = "select count(*) from t_order2 where pay_time >= '"+startTime+"' and pay_time <= '"+endTime+"' and amount <=100000";
+       Long payCountDb = Db.queryLong(payCountSql);
+       if(payCountDb == null){
+       	payCountDb = 0l;
+       }
+       if(payCountDb>0){
+    	   log.info("{} 资金账单已经存在",date);
+    	   return;
+       }
+        log.info("{} 开始下载资金账单",date);
+        	Record config = Db.findFirst("select * from t_pay_config");
+        	String mch_id =config.getStr("mch_id");
+            Map<String, String> params = new HashMap<String, String>();
+            params.put("appid", "wx83a34a499a3db4f1");//商户号
+            params.put("mch_id", mch_id);
+            params.put("nonce_str", System.currentTimeMillis()+"");//随机字符串
+            String partner_key = config.getStr("partner_key");
+            String[] dd = date.split("\\.");
+            StringBuilder sb = new StringBuilder();
+            for (String string : dd) {
+                sb.append(string);
+            }
+            date = sb.toString();
+            params.put("bill_date", date);
+            String certPath;
+            certPath = "/apiclient_cert.p12";
+            params.put("account_type", "Operation");//
+            String stringA = PaymentKit.packageSign(params, false);
+            String stringSignTemp = stringA + "&key=" + partner_key;
+            String sign = HMACSHA256(stringSignTemp,partner_key);
+            params.put("sign", sign);
+            java.net.URL resource = StateMentsUtils.class.getResource(certPath);
+            String file = resource.getFile();
+            String xmlStr = PaymentKit.postSSL("https://api.mch.weixin.qq.com/pay/downloadfundflow", PaymentKit.toXml(params),file,mch_id);
+            String[] split = xmlStr.split("\n");
+            int lineNo = split.length;
+            List<Record> list = new ArrayList<Record>();
+            for (int i = 1; i < lineNo-2; i++) {
+                Record r = new Record();
+                String line = split[i];
+                String[] split2 = line.split(",");
+                if(split2.length<=6){
+                    System.out.println(date);
+                    break;
+                }
+                String payTime = split2[0];
+                String payWxno = split2[2];
+                String payAmount = split2[6];
+                String payNo = split2[10];
+                String mcId = split2[8];
+                payAmount = payAmount.substring(1);
+                payNo = payNo.substring(1);
+                payWxno = payWxno.substring(1);
+                if(WxUtil.isNull(payNo)){
+                    continue;
+                }
+                BigDecimal multiply = new BigDecimal(payAmount).multiply(new BigDecimal(100));
+                int intValue = multiply.intValue();
+                payTime = payTime.substring(1);
+                r.set("pay_time", payTime).set("amount", intValue)
+                        .set("pay_no", payNo).set("mc_id", mcId).set("wx_no", payWxno);
+                list.add(r);
+            }
+
+            WxUtil.batchSave("t_order2", list);
+        log.info("{} 资金账单下载结束",date);
+    }
+
+    public static String HMACSHA256(String data,String key) throws Exception {
+
+        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
+
+        SecretKeySpec secret_key = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
+
+        sha256_HMAC.init(secret_key);
+
+        byte[] array = sha256_HMAC.doFinal(data.getBytes(StandardCharsets.UTF_8));
+
+        StringBuilder sb = new StringBuilder();
+
+        for (byte item : array) {
+
+            sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
+
+        }
+
+        return sb.toString().toUpperCase();
+
+    }
+}

+ 60 - 0
src/main/java/com/qlm/job/MyJob.java

@@ -0,0 +1,60 @@
+package com.qlm.job;
+
+import java.util.Date;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+import com.jfinal.core.Controller;
+import com.jfinal.plugin.activerecord.Db;
+import com.qlm.tongji.service.ISummaryService;
+import com.qlm.tongji.service.impl.SummaryServiceImpl;
+import com.qlm.tools.DateUtils;
+
+
+public class MyJob extends Controller implements Job {
+	
+	private static final Logger logger = LoggerFactory.getLogger(MyJob.class);
+	private ISummaryService summaryService = enhance(SummaryServiceImpl.class);
+
+
+	@Override
+	public void execute(JobExecutionContext jobExecutionContext)
+			throws JobExecutionException {
+		logger.info("定时统计执行..." + new Date());
+		summaryService.addSummary();
+//		updDayCount();
+	}
+
+	/**
+	 * 定时将t_god表中dayCount字段清零
+	 */
+	public static void updDayCount(){
+		String sql = "update t_user set day_count=0";
+		Db.update(sql);
+		logger.info(DateUtils.getStringFullDate()+" 清零dayCount");
+	}
+
+}

+ 20 - 0
src/main/java/com/qlm/log/Log.java

@@ -0,0 +1,20 @@
+package com.qlm.log;
+
+import org.slf4j.LoggerFactory;
+
+public class Log{
+	
+	private static org.slf4j.Logger log = LoggerFactory.getLogger(Log.class);
+	
+	public static void info(String msg){
+			log.info(msg);
+	}
+	
+	public static void info(String msg,Object o){
+		log.info(msg,o);
+	}
+	
+	public static void error(String msg,Object o){
+		log.error(msg,o);
+	}
+}

+ 15 - 0
src/main/java/com/qlm/log/LogerFactory.java

@@ -0,0 +1,15 @@
+package com.qlm.log;
+
+import com.jfinal.log.ILogFactory;
+import com.jfinal.log.Log;
+
+public class LogerFactory implements ILogFactory{
+
+	public Log getLog(Class<?> clazz) {
+		return new Logger(clazz);
+	}
+
+	public Log getLog(String name) {
+		return new Logger(name);
+	}
+}

+ 106 - 0
src/main/java/com/qlm/log/Logger.java

@@ -0,0 +1,106 @@
+package com.qlm.log;
+
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.log.Log;
+
+public class Logger extends Log {
+	private org.slf4j.Logger log;
+
+	public Logger(Class<?> clazz) {
+		log = LoggerFactory.getLogger(clazz);
+	}
+
+	public Logger(String name) {
+		log = LoggerFactory.getLogger(name);
+	}
+
+	@Override
+	public void debug(String message) {
+		log.debug(message);
+	}
+
+	@Override
+	public void debug(String message, Throwable t) {
+		log.debug(message, t);
+
+	}
+
+	@Override
+	public void info(String message) {
+		log.info(message);
+
+	}
+
+	@Override
+	public void info(String message, Throwable t) {
+		log.info(message, t);
+
+	}
+
+	@Override
+	public void warn(String message) {
+		log.warn(message);
+
+	}
+
+	@Override
+	public void warn(String message, Throwable t) {
+		log.warn(message, t);
+
+	}
+
+	@Override
+	public void error(String message) {
+		log.error(message);
+
+	}
+
+	@Override
+	public void error(String message, Throwable t) {
+		log.error(message, t);
+
+	}
+
+	@Override
+	public void fatal(String message) {
+
+	}
+
+	@Override
+	public void fatal(String message, Throwable t) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public boolean isDebugEnabled() {
+		// TODO Auto-generated method stub
+		return true;
+	}
+
+	@Override
+	public boolean isInfoEnabled() {
+		// TODO Auto-generated method stub
+		return true;
+	}
+
+	@Override
+	public boolean isWarnEnabled() {
+		// TODO Auto-generated method stub
+		return true;
+	}
+
+	@Override
+	public boolean isErrorEnabled() {
+		// TODO Auto-generated method stub
+		return true;
+	}
+
+	@Override
+	public boolean isFatalEnabled() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+}

+ 69 - 0
src/main/java/com/qlm/poi/Data.java

@@ -0,0 +1,69 @@
+package com.qlm.poi;
+
+import java.io.Serializable;
+
+public class Data implements Serializable{
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	
+	private String city;
+	private String id;
+	private String addr;
+	private String date;
+	private Long start_code;
+	private Long end_code;
+	private String module_name;
+	
+	public String getCity() {
+		return city;
+	}
+	public void setCity(String city) {
+		this.city = city;
+	}
+	public String getId() {
+		return id;
+	}
+	public void setId(String id) {
+		this.id = id;
+	}
+	public String getAddr() {
+		return addr;
+	}
+	public void setAddr(String addr) {
+		this.addr = addr;
+	}
+	public Long getStart_code() {
+		return start_code;
+	}
+	public void setStart_code(Long start_code) {
+		this.start_code = start_code;
+	}
+	public Long getEnd_code() {
+		return end_code;
+	}
+	public void setEnd_code(Long end_code) {
+		this.end_code = end_code;
+	}
+	public String getModule_name() {
+		return module_name;
+	}
+	public void setModule_name(String module_name) {
+		this.module_name = module_name;
+	}
+	public String getDate() {
+		return date;
+	}
+	public void setDate(String date) {
+		this.date = date;
+	}
+	@Override
+	public String toString() {
+		return "Data [city=" + city + ", id=" + id + ", addr=" + addr + ", date="
+				+ date + ", start_code=" + start_code + ", end_code="
+				+ end_code + ", module_name=" + module_name + "]";
+	}
+	
+	
+}

+ 46 - 0
src/main/java/com/qlm/poi/ExcelHeader.java

@@ -0,0 +1,46 @@
+package com.qlm.poi;
+
+/**
+ * 导出的header
+ * @author gp62
+ *
+ */
+public class ExcelHeader {
+	/**
+	 * 默认列宽为20
+	 */
+	private int colWidth = 20*256;
+	/**
+	 * 该列的中文名
+	 */
+	private String name;
+	/**
+	 * 该列的key,从record对象读取的值
+	 */
+	private String key;
+	public int getColWidth() {
+		return colWidth;
+	}
+	public void setColWidth(int colWidth) {
+		this.colWidth = colWidth;
+	}
+	public String getName() {
+		return name;
+	}
+	public void setName(String name) {
+		this.name = name;
+	}
+	public String getKey() {
+		return key;
+	}
+	public void setKey(String key) {
+		this.key = key;
+	}
+	public ExcelHeader(String name, String key) {
+		super();
+		this.name = name;
+		this.key = key;
+	}
+	
+	
+}

+ 632 - 0
src/main/java/com/qlm/poi/ExcelUtil.java

@@ -0,0 +1,632 @@
+package com.qlm.poi;
+import java.io.File;  
+import java.io.FileInputStream;  
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;  
+import java.io.InputStream;  
+import java.io.OutputStream;  
+import java.lang.reflect.Field;  
+import java.lang.reflect.Method;  
+import java.text.SimpleDateFormat;  
+import java.util.ArrayList;  
+import java.util.Arrays;  
+import java.util.Date;  
+import java.util.Iterator;  
+import java.util.List;  
+import java.util.Map;  
+
+import org.apache.commons.collections.map.ListOrderedMap;
+import org.apache.commons.lang.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;  
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.DateUtil;  
+import org.apache.poi.ss.usermodel.Row;  
+import org.apache.poi.ss.usermodel.Sheet;  
+import org.apache.poi.ss.usermodel.Workbook;  
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
+import org.apache.poi.xssf.usermodel.XSSFCell;  
+import org.apache.poi.xssf.usermodel.XSSFRow;  
+import org.apache.poi.xssf.usermodel.XSSFSheet;  
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
+
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.plugin.activerecord.Record;
+
+  
+/** 
+ * Excel工具类,没有硬编码,修改时不要添加硬编码代码 
+ * @author WSF 
+ * 
+ */  
+@SuppressWarnings("unchecked")  
+public class ExcelUtil {  
+      
+    private ExcelUtil(){};  
+    private static List<String> columns;//要解析excel中的列名  
+    private static int sheetNum = 0;//要解析的sheet下标  
+    private static boolean dynamicColumn = false;//是否  
+    private static Map<String, String> dynamicMapConfig  = new ListOrderedMap();//动态列配置文件  
+    /** 
+     * poi读取excel 
+     * @return 
+     */  
+    public static String readExcel(File file) throws Exception{  
+        StringBuilder retJson = new StringBuilder();  
+        InputStream inStream = null; 
+        String filePath = file.getPath();
+        
+        try{
+        	if(StringUtils.isBlank(filePath)) {
+                throw new IllegalArgumentException("参数错误!!!") ;
+            }
+            if(filePath.trim().toLowerCase().endsWith("xls")) {
+            	inStream = new FileInputStream(file);
+            	HSSFWorkbook workbook = new HSSFWorkbook(inStream);
+	            HSSFSheet sheet = workbook.getSheetAt(sheetNum);//获得表  
+	            int lastRowNum = sheet.getLastRowNum();//最后一行
+	            System.out.println("lastRowNum="+lastRowNum);
+	            retJson.append("[");  
+	            for(int i = 0 ;i < lastRowNum;i++){  
+	                HSSFRow row = sheet.getRow(i+1);//获得行  
+	                String rowJson = readExcelRow(row);  
+	                retJson.append(rowJson);  
+	                if(i<lastRowNum-1)  
+	                retJson.append(",");  
+	            }  
+	            retJson.append("]"); 
+            } else if(filePath.trim().toLowerCase().endsWith("xlsx")) {
+            	  inStream = new FileInputStream(file);
+	              XSSFWorkbook workbook = new XSSFWorkbook(inStream);  
+	              XSSFSheet sheet = (XSSFSheet) workbook.getSheetAt(sheetNum);  
+	              int lastRowNum = sheet.getLastRowNum();//最后一行  
+	              retJson.append("[");  
+	              for(int i = 0 ;i < lastRowNum;i++){  
+	                  XSSFRow row = sheet.getRow(i+1);//获得行  
+	                  String rowJson = readExcelRow(row);  
+	                  retJson.append(rowJson);  
+	                  if(i<lastRowNum-1)  
+	                      retJson.append(",");  
+	              }  
+	              retJson.append("]");
+            } else {
+                 new IllegalArgumentException("不支持除:xls/xlsx以外的文件格式!!!") ;
+            }
+        }catch(Exception e){
+        	e.printStackTrace();
+        	throw e;
+        }
+        return retJson.toString();  
+    }  
+    /** 
+     * poi读取excle 生成实体集合 
+     * @param <E> 
+     * @return 
+     */  
+    public static <E> List<E> readExcel(File file,Class<E> clazz) throws Exception{  
+        if(columns==null){  
+            setColumns(clazz);  
+        }  
+        InputStream inStream = null;  
+        List<E> eList = new ArrayList<E>();  
+        try {  
+            inStream = new FileInputStream(file);  
+            HSSFWorkbook workbook = new HSSFWorkbook(inStream);  
+            HSSFSheet sheet = workbook.getSheetAt(sheetNum);//获得表  
+            int lastRowNum = sheet.getLastRowNum();//最后一行  
+            if(dynamicColumn){  
+                //动态列處理  
+                HSSFRow header = sheet.getRow(0);//表頭  
+                List<String> rList = readRow(header);  
+                setDynamicColumn(rList);  
+            }  
+            for(int i = 0 ;i < lastRowNum;i++){  
+                HSSFRow row = sheet.getRow(i+1);//获得行  
+                String rowJson = readExcelRow(row);  
+                E _e = json2Bean(rowJson,clazz);  
+                eList.add(_e);  
+            }  
+        } catch (Exception e) {  
+            try {  
+                inStream = new FileInputStream(file);  
+                XSSFWorkbook workbook = new XSSFWorkbook(inStream);  
+                XSSFSheet sheet = workbook.getSheetAt(sheetNum);  
+                int lastRowNum = sheet.getLastRowNum();//最后一行  
+                if(dynamicColumn){  
+                    //动态列處理  
+                    XSSFRow header = sheet.getRow(0);  
+                    List<String> rList = readRow(header);  
+                    setDynamicColumn(rList);  
+                }  
+                for(int i = 0 ;i < lastRowNum;i++){  
+                    XSSFRow row = sheet.getRow(i+1);//获得行  
+                    String rowJson = readExcelRow(row);  
+                    E _e = json2Bean(rowJson,clazz);  
+                    eList.add(_e);  
+                }  
+            } catch (Exception e1) {  
+                e1.printStackTrace();  
+                throw e1;  
+            }  
+        }finally{  
+            close(null,inStream);  
+        }  
+        return eList;  
+    }  
+    /** 
+     * 动态列配置 
+     */  
+    private static void setDynamicColumn(List<String> headlist) throws Exception{  
+        List<String> tempcolumns = new ArrayList<String>();  
+        for (Iterator<String> iterator = headlist.iterator();iterator.hasNext();) {  
+            String value = iterator.next();  
+            value = value.replace("(", "(");  
+            value = value.replace(")", ")");  
+            value = value.trim();  
+            String key = findKey(value);  
+            if(key==null){  
+                throw new RuntimeException("请上传合法exce!");  
+            }  
+            tempcolumns.add(findKey(value));  
+        }  
+        setColumns(tempcolumns);//重新设置column  
+    }  
+    /** 
+     * 根据value动态找到key值 
+     * @return 
+     */  
+    private static String findKey(String value){  
+        for(Map.Entry<String,String> entryconfig:dynamicMapConfig.entrySet()){  
+            String keyc = entryconfig.getKey();  
+            String valc = entryconfig.getValue();  
+            if(valc.equals(value)){  
+                return keyc;  
+            }  
+        }  
+        return null;  
+    }  
+    /** 
+     * poi读取excle 生成实体集合 
+     * @param file 
+     * @param clazz 
+     * @param exceptscolumns 
+     * @return 
+     */  
+    public static <E> List<E> readExcel(File file,Class<E> clazz,String[] exceptscolumns) throws Exception{  
+        setColumns(clazz,exceptscolumns);  
+        return readExcel(file, clazz);  
+    }  
+    /** 
+     * 读取excle多个sheet到多个对象(对象的顺序固定) 
+     * @param file 
+     * @param clazz 
+     * @return 
+     */  
+    public static <E> List<List<E>> readExcel(File file,Class<E>[] clazz) throws Exception{  
+        List<List<E>>  eliLists = new ArrayList<List<E>>();//[clazz.length];  
+        int i = 0;  
+        for(Class<E> cls:clazz){  
+            setColumns(null,null);  
+            setSheetNum(i++);  
+            List<E> eList = readExcel(file, cls);  
+            eliLists.add(eList);  
+        }  
+        return eliLists;  
+    }  
+    /** 
+     * 将json转换为Bean实例 
+     * @param <E> 
+     * @return 
+     */  
+    private static <E> E json2Bean(String json,Class<E> clazz) throws Exception{  
+        JSONObject jsonObj = JSONObject.parseObject(json);  
+        Method[] methods = clazz.getDeclaredMethods();  
+        try {  
+            E _e = clazz.newInstance();  
+            for(Method m:methods){  
+                String name = m.getName();  
+                if(name.startsWith("set")){  
+                    String keyPrev = name.substring(3,4).toLowerCase();  
+                    String keyNext = name.substring(4);  
+                    String val = "";  
+                    try {  
+                        val = jsonObj.getString(keyPrev+keyNext);  
+                    } catch (Exception e) {  
+                        val = "";  
+                    }  
+                    m.invoke(_e, val);  
+                }  
+            }  
+            return _e;  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            throw e;  
+        }  
+    }  
+    /** 
+     * 读取行值 
+     * @return 
+     */  
+    private static String readExcelRow(HSSFRow row){  
+        StringBuilder rowJson = new StringBuilder();
+        System.out.println("row="+row);
+        int lastCellNum = row.getPhysicalNumberOfCells();//最后一个单元格  
+        System.out.println("lastCellNum="+lastCellNum);
+        rowJson.append("{");  
+        for(int i = 0 ;i<lastCellNum;i++){  
+            HSSFCell cell = row.getCell(i);  
+            String cellVal = readCellValue(cell);
+            System.out.println("cellVal="+cellVal);
+            rowJson.append(toJsonItem(columns.get(i), cellVal));  
+            if(i<lastCellNum-1)  
+                rowJson.append(",");  
+        }  
+        rowJson.append("}");  
+        return rowJson.toString();  
+    }  
+    /** 
+     * 读取行值 
+     * @return 
+     */  
+    private static String readExcelRow(XSSFRow row){  
+        StringBuilder rowJson = new StringBuilder();  
+        int lastCellNum = ExcelUtil.columns.size();//最后一个单元格  
+        rowJson.append("{");  
+        for(int i = 0 ;i<lastCellNum;i++){  
+            XSSFCell cell = row.getCell(i);  
+            String cellVal = readCellValue(cell);  
+            rowJson.append(toJsonItem(columns.get(i), cellVal));  
+            if(i<lastCellNum-1)  
+                rowJson.append(",");  
+        }  
+        rowJson.append("}");  
+        return rowJson.toString();  
+    }  
+      
+    /** 
+     * 读取行生称list 
+     * @return 
+     */  
+    private static List<String> readRow(XSSFRow row){  
+        List<String> ret = new ArrayList<String>();  
+        int cellcount = row.getLastCellNum();  
+        for(int i = 0 ;i < cellcount;i++){  
+            XSSFCell cell  = row.getCell(i);  
+            String cellval = readCellValue(cell);  
+            if(cellval.trim().length()>0){  
+                ret.add(cellval);  
+            }  
+        }  
+        return ret;  
+    }  
+    /** 
+     * 读取行生称list 
+     * @return 
+     */  
+    private static List<String> readRow(HSSFRow row){  
+        List<String> ret = new ArrayList<String>();  
+        int cellcount = row.getLastCellNum();  
+        for(int i = 0 ;i < cellcount;i++){  
+            HSSFCell cell  = row.getCell(i);  
+            String cellval = readCellValue(cell);  
+            if(cellval.trim().length()>0){  
+                ret.add(cellval);  
+            }  
+        }  
+        return ret;  
+    }  
+  
+    /** 
+     * 读取单元格的值 
+     * @param hssfCell 
+     * @return 
+     */  
+    @SuppressWarnings("static-access")  
+    private static String readCellValue(HSSFCell hssfCell) {  
+        if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {  
+            return String.valueOf(hssfCell.getBooleanCellValue());  
+        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {  
+            short format = hssfCell.getCellStyle().getDataFormat();  
+            SimpleDateFormat sdf = null;  
+            String str_temp = "";  
+            if(format == 14 || format == 31 || format == 57 || format == 58){  
+                //日期  
+                sdf = new SimpleDateFormat("yyyy/MM/dd");  
+                double value = hssfCell.getNumericCellValue();  
+                Date date = DateUtil.getJavaDate(value);  
+                str_temp = sdf.format(date);  
+            }else if(format == 10) {  
+                //百分比  
+                str_temp = hssfCell.getNumericCellValue()+"";  
+            }else {  
+//                hssfCell.setCellType(1);//设置为String 
+            	sdf = new SimpleDateFormat("yyyy/MM/dd");
+                str_temp = sdf.format(hssfCell.getDateCellValue());//得到值 
+            } 
+            System.out.println("str_temp="+str_temp);
+            return str_temp;  
+        }else if(hssfCell.getCellType() == hssfCell.CELL_TYPE_FORMULA){  
+            int val = ((Cell) hssfCell).getCachedFormulaResultType();  
+            return val+"";  
+        } else {  
+            return String.valueOf(hssfCell.getRichStringCellValue());  
+        }  
+    }  
+    /** 
+     * 读取单元格的值 
+     * @param hssfCell 
+     * @return 
+     */  
+    @SuppressWarnings("static-access")  
+    private static String readCellValue(XSSFCell sssfCell) {  
+        if (sssfCell.getCellType() == sssfCell.CELL_TYPE_BOOLEAN) {  
+            return String.valueOf(sssfCell.getBooleanCellValue());  
+        } else if (sssfCell.getCellType() == sssfCell.CELL_TYPE_NUMERIC) {  
+            short format = sssfCell.getCellStyle().getDataFormat();  
+            SimpleDateFormat sdf = null;  
+            String str_temp = "";  
+            if(format == 14 || format == 31 || format == 57 || format == 58){  
+                //日期  
+                sdf = new SimpleDateFormat("yyyy/MM/dd");  
+                double value = sssfCell.getNumericCellValue();  
+                Date date = DateUtil.getJavaDate(value);  
+                str_temp = sdf.format(date);  
+            }else if(format == 10) {  
+                //百分比  
+                str_temp = sssfCell.getNumericCellValue()+"";  
+            }else {  
+                sssfCell.setCellType(1);//设置为String  
+                str_temp = String.valueOf(sssfCell.getRichStringCellValue());//得到值  
+            }  
+            return str_temp;  
+        }else if(sssfCell.getCellType() == sssfCell.CELL_TYPE_FORMULA){  
+            int val = sssfCell.getCachedFormulaResultType();  
+            return val+"";  
+        }else {  
+            return String.valueOf(sssfCell.getRichStringCellValue());  
+        }  
+    }  
+    /** 
+     * 转换为json对 
+     * @return 
+     */  
+    private static String toJsonItem(String name,String val){  
+        return "\""+name+"\":\""+val+"\"";  
+    }  
+    /** 
+     * 关闭io流 
+     * @param fos 
+     * @param fis 
+     */  
+    private static void close(OutputStream out, InputStream in) {  
+        if (in != null) {  
+            try {  
+                in.close();  
+            } catch (IOException e) {  
+                System.out.println("InputStream关闭失败");  
+                e.printStackTrace();  
+            }  
+        }  
+        if (out != null) {  
+            try {  
+                out.close();  
+            } catch (IOException e) {  
+                System.out.println("OutputStream关闭失败");  
+                e.printStackTrace();  
+            }  
+        }  
+    }  
+    /** 
+     * 填出数据到excel book中 
+     * @param book 
+     * @param data 
+     * @param sheetname 
+     * @param titles 
+     * @param columns 
+     */  
+    @SuppressWarnings("rawtypes")
+	public static void data2Book(Workbook book,List<? extends Object> data,String sheetname,String[] titles,String[] columns) throws Exception{  
+        Sheet sheet = book.createSheet(sheetname);  
+        Row th = sheet.createRow((short)0);//标题行  
+        for(int i = 0 ;i <titles.length;i++){  
+            Cell cell = th.createCell(i);  
+            cell.setCellValue(titles[i]);  
+        }  
+        Object _d = data.get(0);  
+        if(_d instanceof Map){  
+            //Map集合  
+            for (int j = 0;j<data.size();j++) {  
+                Map _dm = (Map)data.get(j);  
+                Row tr = sheet.createRow((short)(j+1));//内容行  
+                for(int k = 0 ;k <columns.length;k++){  
+                    Cell cell = tr.createCell(k);  
+                    Object val = _dm.get(columns[k]);  
+                    String value = val==null?"":val.toString();  
+                    cell.setCellValue(value);  
+                }  
+                  
+            }  
+        }else {  
+            //Bean集合  
+            for (int j = 0;j<data.size();j++) {  
+                Object _do = data.get(j);  
+                Row tr = sheet.createRow((short)(j+1));//内容行  
+                for(int k = 0 ;k <columns.length;k++){  
+                    String column = columns[k];  
+                    Method method = getTargetGetMethod(_do, column);//获取目标方法  
+                    try {  
+                        Cell cell = tr.createCell(k);  
+                        Object val = method.invoke(_do);  
+                        String value = val==null?"":val.toString();  
+                        value = value.replace("00:00:00.0","");//处理时间中非法字符  
+                        cell.setCellValue(value);  
+                    } catch (Exception e) {  
+                        e.printStackTrace();  
+                        throw e;  
+                    }  
+                }  
+                  
+            }  
+        }  
+    }  
+    /** 
+     * 获取bean的指定getter方法 
+     * @param o 
+     * @param name 
+     * @return 
+     */  
+    private static Method getTargetGetMethod(Object o,String name) throws Exception{  
+        try {  
+            String mname  = "get"+name.substring(0,1).toUpperCase()+name.substring(1);  
+            return o.getClass().getMethod(mname);  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+            throw  e;  
+        }   
+    }  
+    /** 
+     * 将bean所有属性放入map中 
+     */  
+    private static <E> void beanProp2List(Class<E> clazz,List<String> excepts){  
+        Field[] fields = clazz.getDeclaredFields();  
+        columns = new ArrayList<String>();//顺序固定可重复  
+        for (int i = 0; i < fields.length; i++) {  
+            Field field = fields[i];  
+            String fieldName = field.getName();  
+            if(excepts!=null&&excepts.contains(fieldName))continue;  
+            columns.add(fieldName);  
+        }  
+    }  
+      
+    public static List<String> getColumns() {  
+        return ExcelUtil.columns;  
+    }  
+    public static void setColumns(List<String> columns) {  
+        ExcelUtil.columns = columns;  
+    }  
+    public static void setColumns(Class<?> clazz){  
+        beanProp2List(clazz,null);  
+    }  
+    /** 
+     * 设置列,不包括excepts指定的字段 
+     * @param clazz 
+     * @param excepts 
+     */  
+    public static void setColumns(Class<?> clazz,String[] excepts){  
+        beanProp2List(clazz,Arrays.asList(excepts));  
+    }  
+    public static int getSheetNum() {  
+        return sheetNum;  
+    }  
+    public static void setSheetNum(int sheetNum) {  
+        ExcelUtil.sheetNum = sheetNum;  
+    }  
+    public static boolean isDynamicColumn() {  
+        return dynamicColumn;  
+    }  
+    public static void setDynamicColumn(boolean dynamicColumn) {  
+        ExcelUtil.dynamicColumn = dynamicColumn;  
+    }  
+    public static Map<String, String> getDynamicMapConfig() {  
+        return dynamicMapConfig;  
+    }  
+    public static void setDynamicMapConfig(Map<String, String> dynamicMapConfig) {  
+        ExcelUtil.dynamicMapConfig = dynamicMapConfig;  
+    }  
+     
+    public static List<String>	getColumnsList(HSSFRow row){
+    	ArrayList<String> columnsList = new ArrayList<String>();
+//    	int lastCellNum = row.getPhysicalNumberOfCells();
+//    	for(int i=0;i<lastCellNum){
+//    		
+//    	}
+    	return columnsList;
+    }
+    
+    /**
+     * @param fileName 文件名
+     * @param title  第一行的title
+     * @param ExcelHeader 表头 列顺序 按数组的顺序
+     * @param list  数据列
+     */
+    
+    public static File exportNormal(String fileName,String title,ExcelHeader [] headers,List<Record> list){
+    	File exportExcel =new File("exportExcel");
+    	if(!exportExcel.exists()){
+    		exportExcel.mkdir();
+    	}
+    	File file = new File("exportExcel"+File.separator+fileName+".xlsx");
+		try {
+			if(!file.exists()){
+	    		file.createNewFile();
+	    	}
+			FileOutputStream out = new FileOutputStream(file);
+			Workbook workBook = new SXSSFWorkbook(100);
+			Sheet  sheet = workBook.createSheet();
+//			sheet.setDefaultColumnWidth(20);
+			insertHeader(workBook,sheet,headers,title);
+			insertData(list,sheet,headers);
+			workBook.write(out);
+			out.close();
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		return file;
+		
+    }
+	private static void insertData(List<Record> list, Sheet sheet,
+			ExcelHeader[] headers) {
+		int j = 2;
+		for (Record data : list) {
+			Row row1 = sheet.createRow(j);
+			j++;
+			for (int i = 0; i < headers.length; i++) {
+				ExcelHeader header = headers[i];
+				Cell  cell = row1.createCell(i);
+				String key = header.getKey();
+				  Object object = data.get(key);
+				  if(object instanceof Date){
+					  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+					  String format = sdf.format(object);
+					  cell.setCellValue(format); 
+				  }else if(object instanceof Number){
+					  Number a = (Number)object;
+					  cell.setCellValue(a.doubleValue());
+				  }else{
+					  String val = "";
+					  if(object != null){
+						  val = object.toString();
+					  }
+					  cell.setCellValue(val); 
+				  }
+			}
+			  
+		}
+	}
+	private static void insertHeader(Workbook wb, Sheet sheet, ExcelHeader[] headers, String title) {
+		Row row1 = sheet.createRow(0);
+		Cell  headerCell = row1.createCell(0);
+		headerCell.setCellValue(title); 
+		Row row2 = sheet.createRow(1);
+		CellStyle createCellStyle = wb.createCellStyle();
+		createCellStyle.setAlignment(CellStyle.ALIGN_CENTER);
+		createCellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
+		headerCell.setCellStyle(createCellStyle);
+		int i = 0;
+		for (ExcelHeader header : headers) {
+			 Cell  cell = row2.createCell(i);
+			 cell.setCellValue(header.getName()); 
+			 sheet.setColumnWidth(i, header.getColWidth());
+			 i++;
+		}
+		CellRangeAddress codeAreaRegion = new CellRangeAddress(
+				0, 0, 0, i-1);// 起始行号,终止行号, 起始列号,终止列号
+		sheet.addMergedRegion(codeAreaRegion);
+	}
+}  

+ 249 - 0
src/main/java/com/qlm/poi/PoiExcelHelper.java

@@ -0,0 +1,249 @@
+package com.qlm.poi;
+import java.util.ArrayList;  
+
+import org.apache.poi.ss.usermodel.Cell;  
+import org.apache.poi.ss.usermodel.Row;  
+import org.apache.poi.ss.usermodel.Sheet;  
+  
+/** 
+ * Excel统一POI处理类(针对2003以前和2007以后两种格式的兼容处理) 
+ * @author  chengesheng 
+ * @date    2012-5-3 下午03:10:23 
+ * @note    PoiHelper 
+ */  
+public abstract class PoiExcelHelper {  
+    public static final String SEPARATOR = ",";  
+    public static final String CONNECTOR = "-";  
+  
+    /** 获取sheet列表,子类必须实现 */  
+    public abstract ArrayList<String> getSheetList(String filePath);  
+      
+    /** 读取Excel文件数据 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex)throws Exception {  
+        return readExcel(filePath, sheetIndex, "1-", "1-");  
+    }  
+      
+    /** 读取Excel文件数据 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows)throws Exception {  
+        return readExcel(filePath, sheetIndex, rows, "1-");  
+    }  
+      
+    /** 读取Excel文件数据 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String[] columns) {  
+        return readExcel(filePath, sheetIndex, "1-", columns);  
+    }  
+      
+    /** 读取Excel文件数据,子类必须实现 */  
+    public abstract ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, String columns)throws Exception;  
+  
+    /** 读取Excel文件数据 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, String[] columns) {  
+        int[] cols = getColumnNumber(columns);  
+          
+        return readExcel(filePath, sheetIndex, rows, cols);  
+    }  
+  
+    /** 读取Excel文件数据,子类必须实现 */  
+    public abstract ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, int[] cols);  
+      
+    /** 读取Excel文件内容 */  
+    protected ArrayList<ArrayList<String>> readExcel(Sheet sheet, String rows, int[] cols,ArrayList<ArrayList<String>> dataList) {  
+        // 处理行信息,并逐行列块读取数据  
+        String[] rowList = rows.split(SEPARATOR);  
+        for (String rowStr : rowList) {  
+            if (rowStr.contains(CONNECTOR)) {  
+                String[] rowArr = rowStr.trim().split(CONNECTOR);  
+                int start = Integer.parseInt(rowArr[0]) - 1;  
+                int end;  
+                if (rowArr.length == 1) {  
+                    end = sheet.getLastRowNum();  
+                } else {  
+                    end = Integer.parseInt(rowArr[1].trim()) - 1;  
+                }  
+                dataList.addAll(getRowsValue(sheet, start, end, cols));  
+            } else {  
+                dataList.add(getRowValue(sheet, Integer.parseInt(rowStr) - 1, cols));  
+            }  
+        }  
+        return dataList;  
+    }  
+  
+    /** 获取连续行、列数据 */  
+    protected ArrayList<ArrayList<String>> getRowsValue(Sheet sheet, int startRow, int endRow,  
+            int startCol, int endCol) {  
+        if (endRow < startRow || endCol < startCol) {  
+            return null;  
+        }  
+          
+        ArrayList<ArrayList<String>> data = new ArrayList<ArrayList<String>>();  
+        for (int i = startRow; i <= endRow; i++) {  
+            data.add(getRowValue(sheet, i, startCol, endCol));  
+        }  
+        return data;  
+    }  
+  
+    /** 获取连续行、不连续列数据 */  
+    private ArrayList<ArrayList<String>> getRowsValue(Sheet sheet, int startRow, int endRow, int[] cols) {  
+        if (endRow < startRow) {  
+            return null;  
+        }  
+          
+        ArrayList<ArrayList<String>> data = new ArrayList<ArrayList<String>>();  
+        for (int i = startRow; i <= endRow; i++) {  
+            data.add(getRowValue(sheet, i, cols));  
+        }  
+        return data;  
+    }  
+      
+    /** 获取行连续列数据 */  
+    private ArrayList<String> getRowValue(Sheet sheet, int rowIndex, int startCol, int endCol) {  
+        if(endCol < startCol) {  
+            return null;  
+        }  
+          
+        Row row = sheet.getRow(rowIndex);  
+        ArrayList<String> rowData = new ArrayList<String>();  
+        for (int i = startCol; i <= endCol; i++) {  
+            rowData.add(getCellValue(row, i));  
+        }  
+        return rowData;  
+    }  
+      
+    /** 获取行不连续列数据 */  
+    private ArrayList<String> getRowValue(Sheet sheet, int rowIndex, int[] cols) {  
+        Row row = sheet.getRow(rowIndex);  
+        ArrayList<String> rowData = new ArrayList<String>();  
+        for (int colIndex : cols) {  
+            rowData.add(getCellValue(row, colIndex));  
+        }  
+        return rowData;  
+    }  
+      
+    /** 
+     * 获取单元格内容 
+     *  
+     * @param row 
+     * @param column 
+     *            a excel column string like 'A', 'C' or "AA". 
+     * @return 
+     */  
+    protected String getCellValue(Row row, String column) {  
+        return getCellValue(row,getColumnNumber(column));  
+    }  
+  
+    /** 
+     * 获取单元格内容 
+     *  
+     * @param row 
+     * @param col 
+     *            a excel column index from 0 to 65535 
+     * @return 
+     */  
+    private String getCellValue(Row row, int col) {  
+        if (row == null) {  
+            return "";  
+        }  
+        Cell cell = row.getCell(col);  
+        return getCellValue(cell);  
+    }  
+  
+    /** 
+     * 获取单元格内容 
+     *  
+     * @param cell 
+     * @return 
+     */  
+    private String getCellValue(Cell cell) {  
+        if (cell == null) {  
+            return "";  
+        }  
+  
+        String value = cell.toString().trim();  
+        try {  
+            // This step is used to prevent Integer string being output with  
+            // '.0'.  
+            Float.parseFloat(value);  
+            value=value.replaceAll("\\.0$", "");  
+            value=value.replaceAll("\\.0+$", "");  
+            return value;  
+        } catch (NumberFormatException ex) {  
+            return value;  
+        }  
+    }  
+  
+    /** 
+     * Change excel column letter to integer number 
+     *  
+     * @param columns 
+     *            column letter of excel file, like A,B,AA,AB 
+     * @return 
+     */  
+    private int[] getColumnNumber(String[] columns) {  
+        int[] cols = new int[columns.length];  
+        for(int i=0; i<columns.length; i++) {  
+            cols[i] = getColumnNumber(columns[i]);  
+        }  
+        return cols;  
+    }  
+  
+    /** 
+     * Change excel column letter to integer number 
+     *  
+     * @param column 
+     *            column letter of excel file, like A,B,AA,AB 
+     * @return 
+     */  
+    private int getColumnNumber(String column) {  
+        int length = column.length();  
+        short result = 0;  
+        for (int i = 0; i < length; i++) {  
+            char letter = column.toUpperCase().charAt(i);  
+            int value = letter - 'A' + 1;  
+            result += value * Math.pow(26, length - i - 1);  
+        }  
+        return result - 1;  
+    }  
+  
+    /** 
+     * Change excel column string to integer number array 
+     *  
+     * @param sheet 
+     *            excel sheet 
+     * @param columns 
+     *            column letter of excel file, like A,B,AA,AB 
+     * @return 
+     */  
+    protected int[] getColumnNumber(Sheet sheet, String columns) {  
+        // 拆分后的列为动态,采用List暂存  
+        ArrayList<Integer> result = new ArrayList<Integer> ();  
+        String[] colList = columns.split(SEPARATOR);  
+        for(String colStr : colList){  
+            if(colStr.contains(CONNECTOR)){  
+                String[] colArr = colStr.trim().split(CONNECTOR);  
+                int start = Integer.parseInt(colArr[0]) - 1;  
+                int end;  
+                if(colArr.length == 1){  
+                    end = sheet.getLastRowNum();  
+                }else{  
+                    end = Integer.parseInt(colArr[1].trim()) - 1;  
+                }  
+                for(int i=start; i<=end; i++) {  
+                    result.add(i);  
+                }  
+            }else{  
+                result.add(Integer.parseInt(colStr) - 1);  
+            }  
+        }  
+          
+        // 将List转换为数组  
+        int len = result.size();  
+        int[] cols = new int[len];   
+        for(int i = 0; i<len; i++) {  
+            cols[i] = result.get(i).intValue(); 
+            System.out.println("cols[i]="+cols[i]);
+        }  
+  
+        return cols;  
+    } 
+
+}  

+ 74 - 0
src/main/java/com/qlm/poi/PoiExcelHelperImpl03.java

@@ -0,0 +1,74 @@
+package com.qlm.poi;
+import java.io.FileInputStream;  
+import java.io.IOException;
+import java.util.ArrayList;  
+  
+
+
+
+import org.apache.poi.hssf.usermodel.HSSFSheet;  
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;  
+  
+/** 
+ * Excel 读取(97-2003格式) 
+ * @author  chengesheng 
+ * @date    2012-4-27 下午03:39:01 
+ * @note    PoiExcel2k3Helper 
+ */  
+public class PoiExcelHelperImpl03 extends PoiExcelHelper {  
+    /** 获取sheet列表 */  
+    public ArrayList<String> getSheetList(String filePath) {  
+        ArrayList<String> sheetList = new ArrayList<String>(0);  
+        try {  
+            HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filePath));  
+            int i = 0;  
+            while (true) {  
+                try {  
+                    String name = wb.getSheetName(i);  
+                    sheetList.add(name);  
+                    i++;  
+                } catch (Exception e) {  
+                    break;  
+                }  
+            }  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+        }  
+        return sheetList;  
+    }  
+  
+    /** 读取Excel文件内容 
+     * @throws IOException 
+     * @throws Exception */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, String columns) throws Exception {  
+        ArrayList<ArrayList<String>> dataList = new ArrayList<ArrayList<String>> ();  
+            HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filePath));  
+//            HSSFSheet sheet = wb.getSheetAt(sheetIndex);  
+            HSSFSheet sheet = null;
+            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
+				sheet = wb.getSheetAt(i);
+				dataList = readExcel(sheet, rows, getColumnNumber(sheet, columns),dataList);  
+			}
+            
+        return dataList;  
+    }  
+      
+    /** 读取Excel文件内容 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, int[] cols) {  
+        ArrayList<ArrayList<String>> dataList = new ArrayList<ArrayList<String>> ();  
+        try {  
+            HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filePath));  
+//            HSSFSheet sheet = wb.getSheetAt(sheetIndex);  
+            HSSFSheet sheet = null;
+            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
+				sheet = wb.getSheetAt(i);
+				dataList = readExcel(sheet, rows, cols,dataList);  
+			}
+        } catch (Exception e) {  
+            e.printStackTrace();  
+        }  
+        return dataList;  
+    } 
+    
+
+}

+ 69 - 0
src/main/java/com/qlm/poi/PoiExcelHelperImpl07.java

@@ -0,0 +1,69 @@
+package com.qlm.poi;
+import java.io.FileInputStream;  
+import java.util.ArrayList;  
+import java.util.Iterator;  
+  
+
+
+import org.apache.poi.xssf.usermodel.XSSFSheet;  
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
+  
+/** 
+ * Excel 读取(2007+新格式) 
+ * @author  chengesheng 
+ * @date    2012-4-27 下午03:39:01 
+ * @note    PoiExcel2k7Helper 
+ */  
+public class PoiExcelHelperImpl07 extends PoiExcelHelper {  
+    /** 获取sheet列表 */  
+    public ArrayList<String> getSheetList(String filePath) {  
+        ArrayList<String> sheetList = new ArrayList<String>(0);  
+        try {  
+            XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath));  
+            Iterator<XSSFSheet> iterator = wb.iterator();  
+            while (iterator.hasNext()) {  
+                sheetList.add(iterator.next().getSheetName());  
+            }  
+        } catch (Exception e) {  
+            e.printStackTrace();  
+        }  
+        return sheetList;  
+    }  
+  
+    /** 读取Excel文件内容 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, String columns) {  
+        ArrayList<ArrayList<String>> dataList = new ArrayList<ArrayList<String>> ();  
+        try {  
+            XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath));  
+//            XSSFSheet sheet = wb.getSheetAt(sheetIndex);  
+            XSSFSheet sheet = null;
+            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
+				sheet = wb.getSheetAt(i);
+				dataList = readExcel(sheet, rows, getColumnNumber(sheet, columns),dataList);  
+			}
+        } catch (Exception e) {  
+            e.printStackTrace();  
+        }  
+        return dataList;  
+    }  
+      
+    /** 读取Excel文件内容 */  
+    public ArrayList<ArrayList<String>> readExcel(String filePath, int sheetIndex, String rows, int[] cols) {  
+        ArrayList<ArrayList<String>> dataList = new ArrayList<ArrayList<String>> ();  
+        try {  
+            XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath));  
+//            XSSFSheet sheet = wb.getSheetAt(sheetIndex);  
+            XSSFSheet sheet = null;
+            for (int i = 0; i < wb.getNumberOfSheets(); i++) {
+				sheet = wb.getSheetAt(i);
+				dataList = readExcel(sheet, rows, cols,dataList);  
+			}
+//            dataList = readExcel(sheet, rows, cols,dataList);
+        } catch (Exception e) {  
+            e.printStackTrace();  
+        }  
+        return dataList;  
+    } 
+    
+   
+}  

+ 24 - 0
src/main/java/com/qlm/rpc/CacheNotice.java

@@ -0,0 +1,24 @@
+package com.qlm.rpc;
+
+import java.util.List;
+
+import com.jfinal.kit.HttpKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+
+public class CacheNotice {
+	
+	public static void updateScan(){
+		List<Record> find = Db.find("select * from t_url");
+		String path = "/cache/updateHbConfig";
+		for (Record record : find) {
+			String url = record.getStr("url_");
+			try{
+				String string = HttpKit.get(url+path);
+			}catch(Exception e){
+				e.printStackTrace();
+			}
+		}
+	}
+
+}

+ 23 - 0
src/main/java/com/qlm/service/IAdminService.java

@@ -0,0 +1,23 @@
+package com.qlm.service;
+
+import com.jfinal.plugin.activerecord.Record;
+
+/**
+ * @author nommpp
+ * @date 2020/3/2
+ */
+public interface IAdminService {
+    public String getUsersList();
+
+    public boolean save(Record user);
+
+    public boolean enableUser(Integer id);
+
+    public boolean disableUser(Integer id);
+
+    public Record getUserById(Integer id);
+
+    public boolean updateUser(Record user);
+
+    public boolean delUser(Integer id);
+}

+ 27 - 0
src/main/java/com/qlm/service/IAreaHbConfigService.java

@@ -0,0 +1,27 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.AreaHbConfig;
+import com.qlm.view.ResultMsg;
+
+public interface IAreaHbConfigService {
+	public abstract List<Record> findAreaHbConfig();
+	
+	public abstract String findAreaHbConfig(String aoData,Integer configId);
+	
+	public abstract List<Record> findAreaHbConfigRateById(Integer Id);
+	
+	public abstract ResultMsg saveAreaHbConfigInfo(String area,String times);
+	
+	public abstract ResultMsg saveAreaHbConfigRateInfo(String[] money_,String[] rate_,Integer[] time_ids);
+	
+	public abstract ResultMsg updateAreaHbConfigInfo(AreaHbConfig areaHbConfig);
+	
+	public abstract ResultMsg updateAreaHbConfingRateInfo(List<Record> areaHbConfigRateLists);
+
+	public abstract ResultMsg deleteAreaHbConfigInfo(Integer configId);
+	
+	public abstract ResultMsg deleteAreaHbConfigRateInfo(Integer Id);
+}

+ 17 - 0
src/main/java/com/qlm/service/IAuthService.java

@@ -0,0 +1,17 @@
+package com.qlm.service;
+
+import com.qlm.view.ResultMessage;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 登陆权限管理
+ * 
+ * @author David
+ *
+ */
+public interface IAuthService {
+	public abstract AdminView login(AdminView adminView);
+	public abstract boolean pwdCheck(String adminName ,String pwd);	
+	public abstract ResultMessage adminUpd(AdminView adminView);
+	public abstract String getMenuByUserId(AdminView adminView, String contextPath);
+}

+ 13 - 0
src/main/java/com/qlm/service/IHBRateService.java

@@ -0,0 +1,13 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.qlm.entity.HBRate;
+import com.qlm.view.ResultMsg;
+
+public interface IHBRateService {
+	
+	List<HBRate> getHBRateList(Integer type);
+	
+	ResultMsg saveHbrate(String[] money_,String[] rate_,Integer type_,String planName,String [] prizeTypes, int id);
+}

+ 10 - 0
src/main/java/com/qlm/service/IOperatingService.java

@@ -0,0 +1,10 @@
+package com.qlm.service;
+
+import com.qlm.view.OperatingView;
+
+
+public interface IOperatingService {
+	public abstract boolean OperatingRecord(String admin,String Content,String IPAddr);
+	
+	public abstract String OperatingRecordList(String aoData);
+}

+ 12 - 0
src/main/java/com/qlm/service/IProductService.java

@@ -0,0 +1,12 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.view.core.AdminView;
+
+public interface IProductService {
+	public abstract List<Record> getProductInfoList(AdminView loginUser);
+	
+	public abstract Record getProductInfoByType(Integer type);
+}

+ 14 - 0
src/main/java/com/qlm/service/IQrcodeAddService.java

@@ -0,0 +1,14 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.qlm.view.core.AdminView;
+
+public interface IQrcodeAddService {
+	
+	public List<String> getPropertiesUrl();
+	
+	public String getZipFilePath(String url,String code,Integer num,String filePath,Integer addNum,String id,Integer type,String area,AdminView loginUser);
+	
+	public Integer getProgress(String id);
+}

+ 20 - 0
src/main/java/com/qlm/service/IRecordService.java

@@ -0,0 +1,20 @@
+package com.qlm.service;
+
+import com.qlm.entity.Record;
+import com.qlm.view.ResultMessage;
+import com.qlm.view.core.AdminView;
+
+public interface IRecordService {
+	/**
+	 * 查询按时间倒序排列的产码记录
+	 * @param loginUser 
+	 * @return
+	 */
+	public String getRecordList(String aoData, AdminView loginUser);
+	
+	public ResultMessage setValid(Integer id,Integer valid,Integer config_id);
+	
+	public ResultMessage updateArea(Integer id,Integer config_id);
+
+	public ResultMessage activeCode(Record record);
+}

+ 20 - 0
src/main/java/com/qlm/service/IResService.java

@@ -0,0 +1,20 @@
+package com.qlm.service;
+
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.Res;
+
+public interface IResService {
+	public String getResList();
+	
+	public String getMenuTree();
+	
+	public boolean del(Integer id);
+	
+	public Record getById(Integer id);
+	
+	public String getResNameByPid(Integer pid);
+	
+	public boolean add(Res res);
+	
+
+}

+ 26 - 0
src/main/java/com/qlm/service/IRoleService.java

@@ -0,0 +1,26 @@
+package com.qlm.service;
+
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.view.core.AdminView;
+
+import java.util.List;
+
+public interface IRoleService {
+	public String getRolesList(AdminView loginUser);
+	
+	public List<Record> getAllRoles();
+	
+	public boolean getRoleByName(String name);
+	
+	public boolean save(String roleName,AdminView loginUser);
+	
+	public Record getRoleById(Integer id);
+	
+	public boolean updateRole(Record role);
+	
+	public boolean delRole(Integer id);
+	
+	public String getAuthById(Integer roleId);
+	
+	public boolean saveRoleAuth(String[] auths, Integer roleId);
+}

+ 26 - 0
src/main/java/com/qlm/service/ISearchService.java

@@ -0,0 +1,26 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.core.AdminView;
+
+public interface ISearchService {
+	
+	ResultMsg searchByQrcode(String qrcode);
+	
+	List<Record> getAreaCodeByRecord(AdminView loginUser);
+	
+	ResultMsg searchByDateAndMoney(String date,String end_time,String type_,String area_code);
+
+	ResultMsg searchByCurrentAndMoney(String type_,String area_code);
+	
+	String searchByCountAndMoney(Integer counts,Integer dayCounts,Integer money,String date,String aoData, AdminView loginUser);
+	
+	ResultMsg searchAreaHbBySendTimeAndType(String startDate, String endDate,String type_);
+
+	List<Record> totla(String[] type,String startTime,String endTime,Integer group);
+
+	List<Record> totla(String[] type);
+}

+ 19 - 0
src/main/java/com/qlm/service/IStatisticService.java

@@ -0,0 +1,19 @@
+package com.qlm.service;
+
+import com.qlm.view.EchartDataView;
+
+public interface IStatisticService {
+
+	/**
+	 * 根据日期时间段获取echart对象的XY轴数据
+	 * 
+	 * @return
+	 */
+	EchartDataView getEDV(String startDate, String endDate);
+	
+	/**
+	 * 获取当天每小时统计数据 echart对象的XY轴数据
+	 * @return
+	 */
+	EchartDataView getEDVOneDay();
+}

+ 17 - 0
src/main/java/com/qlm/service/IUnPayInfoService.java

@@ -0,0 +1,17 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.qlm.view.UnPayView;
+import com.qlm.view.core.AdminView;
+
+
+public interface IUnPayInfoService {
+	/**
+	 * 获取未发红包列表
+	 * @param loginUser 
+	 * @param aoData 
+	 * @return
+	 */
+	public List<UnPayView> getUnPayInfo(AdminView loginUser);
+}

+ 43 - 0
src/main/java/com/qlm/service/TypeServices.java

@@ -0,0 +1,43 @@
+package com.qlm.service;
+
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 品类操作
+ * @author lds
+ * @date 2019/11/01
+ */
+public class TypeServices {
+    
+    public static List<Record> getTypes(AdminView loginUser){
+        return Db.find("select * from t_product where uid = ?",loginUser.getId());
+    }
+    
+    public static Record getTypeById(Integer id){
+        return Db.findById("t_product", id);
+    }
+    
+    public static Record addType(Record type,AdminView loginUser){
+    	type.set("uid", loginUser.getId());
+        return Db.save("t_product", type)?type:null;
+    }
+    
+    public static Record updateType(Record type){
+        Db.update("t_product", type);
+        return Db.findById("t_product", JFinalUtil.getInt("id", type));
+    }
+    
+    public static boolean deleteType(Integer id){
+        return Db.deleteById("t_product", id);
+    }
+    
+    public static int typeId(){
+        return Db.queryInt("select max(type_) typeId from t_product").intValue();
+    }
+
+}

+ 75 - 0
src/main/java/com/qlm/service/UploadService.java

@@ -0,0 +1,75 @@
+package com.qlm.service;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.tools.WxUtil;
+
+public class UploadService {
+
+	@Before(Tx.class)
+	public void upload(String data){
+		JSONObject parseObject = JSONObject.parseObject(data);
+		String deviceId = parseObject.getString("d");
+		List<Record> list = new ArrayList();
+		List<Record> xiangList = new ArrayList<Record>();
+		JSONArray jsonArray = parseObject.getJSONArray("l");
+		Map<String,JSONObject> masterMap = new HashMap<String, JSONObject>();
+		for (int i = 0; i < jsonArray.size(); i++) {
+			JSONObject jsonObject = jsonArray.getJSONObject(i);
+			String master = jsonObject.getString("m");
+			String childCode = jsonObject.getString("i");
+	
+			if("nodata".equals(master)){
+				Db.update("update jinzai_upload_record set master_code = null where child_code = ?",childCode);
+			}else{
+				JSONObject jsonObject2 = masterMap.get(master);
+				if(jsonObject2 == null){
+					masterMap.put(master, jsonObject)	;
+				}
+				Record info = new Record();
+				info.set("child_code", childCode).set("master_code", master)
+				.set("create_time", new Date());
+				list.add(info);
+			}
+		}
+		Set<Entry<String,JSONObject>> entrySet = masterMap.entrySet();
+		
+		for (Entry<String, JSONObject> entry : entrySet) {
+			String master = entry.getKey();
+			JSONObject jsonObject = entry.getValue();
+			String addTime = jsonObject.getString("g");
+			String duoma = jsonObject.getString("t");
+			String taskNo = jsonObject.getString("s");
+			String kouwei = jsonObject.getString("k");
+			String pinxiang = jsonObject.getString("p");
+			String productDate = jsonObject.getString("d");
+			
+			String banzu = jsonObject.getString("b");
+			Record masterInfo = new Record();
+			
+			
+			masterInfo.set("id", master).set("create_time", new Date()).set("produce_date", productDate)
+			.set("duo_code", duoma).set("device_no", deviceId).set("guo_time", addTime)
+			.set("pinxiang", pinxiang).set("kouwei", kouwei).set("task_no", taskNo).set("banzu", banzu);
+			xiangList.add(masterInfo);
+		}
+		
+		
+		WxUtil.batchSaveIgnore("jinzai_upload_child", list, "");
+	
+		
+		WxUtil.batchSaveIgnore("jinzai_upload_master", xiangList, "");
+	}
+}

+ 54 - 0
src/main/java/com/qlm/service/WmesService.java

@@ -0,0 +1,54 @@
+package com.qlm.service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.kit.HttpKit;
+import com.jfinal.plugin.activerecord.Db;
+
+public class WmesService {
+
+	public static void main(String[] args) {
+		uploadData();
+	}
+	
+	public static void uploadData(){
+		
+		JSONObject bigData = new JSONObject();
+		JSONObject data = new JSONObject();
+		
+		bigData.put("data", data);
+		
+		
+		JSONArray header = new JSONArray();
+		
+		JSONObject obj1 = new JSONObject();
+		
+		data.put("header", header);
+		
+		
+		obj1.put("warehouseid", "JZPJ");
+		obj1.put("asnno", "2406271531351220000");
+		
+		obj1.put("serialno", "406271531421010101684000");
+		
+		obj1.put("sku", "1001A81000000031AK8R");
+		
+		
+		obj1.put("traceId", "406271531401010101549000");
+		
+		obj1.put("addtime", "2024-06-25 15:59:16");
+		obj1.put("udf06", "tm");
+		
+		header.add(obj1);
+		
+	      Map<String,String> headers = new HashMap<>();
+          headers.put("Content-Type","application/json");
+		System.out.println(bigData);
+		String post = HttpKit.post("http://192.168.0.184:18080/datahubjson/WMS_EM/?method=QRCODE&apptoken=BAB75C8B843F1C92AC3FFE3BD2A06A5F&timestamp=2024-06-25%2015:59:16&sign=1&format=JSON", bigData.toString(),headers);
+		
+		System.out.println(post);
+	}
+}

+ 244 - 0
src/main/java/com/qlm/service/impl/AreaHbConfigServiceImpl.java

@@ -0,0 +1,244 @@
+package com.qlm.service.impl;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.DbKit;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.AreaHbConfig;
+import com.qlm.entity.AreaHbConfigRate;
+import com.qlm.rpc.CacheNotice;
+import com.qlm.service.IAreaHbConfigService;
+import com.qlm.tools.Common;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.view.AreaHbConfigView;
+import com.qlm.view.ResultMsg;
+
+public class AreaHbConfigServiceImpl implements IAreaHbConfigService {
+
+	@Override
+	public List<Record> findAreaHbConfig() {
+		String sql = "select id,config_id,name_ from t_qcode_hb_config GROUP BY config_id ORDER BY config_id";
+		return Db.find(sql);
+	}
+
+	@Override
+	public String findAreaHbConfig(String aoData, Integer configId) {
+		// TODO Auto-generated method stub
+		StringBuilder sbSql = new StringBuilder(
+				"select id,config_id,name_,start_time,end_time from t_qcode_hb_config where config_id = ? ORDER BY config_id");
+		List<Record> AreaHbConfigRecords = Db.find(sbSql.toString(), configId);
+
+		List<Object> AHCList = new ArrayList<Object>();
+		int index = 1;
+		for (Record record : AreaHbConfigRecords) {
+			AreaHbConfigView ahcv = new AreaHbConfigView();
+			ahcv.setSequenceNumber(index);
+			Integer config_id = record.getInt("config_id");
+			ahcv.setConfig_id(config_id);
+			ahcv.setName(record.getStr("name_"));
+			Integer id = record.getInt("id");
+			ahcv.setId(id);
+			String times = Common
+					.getStringTime(record.getTime("start_time"), 1)
+					+ "~"
+					+ Common.getStringTime(record.getTime("end_time"), 1);
+			ahcv.setTimes(times);
+			String rate_money = "<ol style='list-style-type:none'>";
+			List<Record> rate_moneyList = Db.find("select id,rate_,money_,time_id from t_qcode_hb_config_rate where time_id = ?",id);
+			if(rate_moneyList == null){
+				rate_money = "还未设置红包金额和概率";
+			}else{
+				for(Record rate_moneyRecord :rate_moneyList){
+					String rate = JFinalUtil.getStr("rate_", rate_moneyRecord);
+					Double money = JFinalUtil.getInt("money_", rate_moneyRecord).doubleValue()/100;
+					rate_money+= "<li style='line-height:30px;'>"+money+"元("+ rate +"%)</li>";
+				}
+			}			
+			rate_money+="</ol>";
+			ahcv.setRate_money(rate_money);
+			AHCList.add(ahcv);
+			index++;
+		}
+		return Common.dataTableSearch(aoData, AHCList);
+	}
+
+	@Override
+	public List<Record> findAreaHbConfigRateById(Integer Id) {
+		// TODO Auto-generated method stub
+		StringBuilder sbSql = new StringBuilder(
+				"select id,rate_,money_,time_id from t_qcode_hb_config_rate where time_id = ?");
+		sbSql.append("  order by id");
+		List<Record> AreaHbConfigRateRecords = Db.find(sbSql.toString(), Id);
+		return AreaHbConfigRateRecords;
+	}
+
+	@Override
+	public ResultMsg saveAreaHbConfigInfo(String area,String times) {
+		// TODO Auto-generated method stub
+		ResultMsg rm = new ResultMsg();
+		Integer configId = findConfigId();		
+		String[] timess = times.split(",");
+		for(String str : timess){
+			String[] timesss = str.split("-");
+			new AreaHbConfig().set("name_", area).set("start_time", timesss[0]).set("end_time", timesss[1]).set("config_id", configId).save();
+		}
+		rm.setStatus(true);
+		rm.setMsg("时间段配置保存成功");		
+		return rm;
+	}
+	
+	private static Integer findConfigId(){
+		int i = 0;
+		while(findConfigId(i) != null){
+			i++;
+		}
+		return i;
+	}
+	
+	private static Record findConfigId(Integer configId){
+		return  Db.findFirst("select id from t_qcode_hb_config where config_id = ?",configId);
+	}
+
+	@Override
+	public ResultMsg saveAreaHbConfigRateInfo(String[] money_, String[] rate_, Integer[] time_ids) {
+		// TODO Auto-generated method stub
+		ResultMsg rm = new ResultMsg();
+		if (!Common.isNullOrEmpty(money_) && !Common.isNullOrEmpty(money_)
+				&& !Common.isNullOrEmpty(time_ids)
+				&& time_ids.length == money_.length
+				&& money_.length == rate_.length&& rate_.length > 0) {
+			//删除老数据
+			Integer time_id = time_ids[0];
+			Db.update("delete from t_qcode_hb_config_rate where time_id = ?",time_id);
+			
+			// 插入新数据
+			int len = money_.length;
+			for (int i = 0; i < len; i++) {
+				int money = new BigDecimal(money_[i]).multiply(
+						new BigDecimal(100)).intValue();
+				String rate = rate_[i];
+				time_id = time_ids[i];
+				new AreaHbConfigRate().set("money_", money)
+						.set("rate_", rate).set("time_id", time_id).save();
+			}
+			rm.setStatus(true);
+			rm.setMsg("红包配置保存成功");
+		} else {
+			rm.setStatus(false);
+			rm.setMsg("网络连接错误");
+		}
+		return rm;
+	}
+
+	@Override
+	public ResultMsg updateAreaHbConfigInfo(AreaHbConfig areaHbConfig) {
+		// TODO Auto-generated method stub
+		boolean result = areaHbConfig.update();
+		if (!result) {
+			return (ResultMsg) new ResultMsg().set("msg", "connection fail")
+					.set("status", false);
+		}
+		return (ResultMsg) new ResultMsg().set("msg", "保存成功").set("status",
+				true);
+	}
+
+	@Override
+	public ResultMsg updateAreaHbConfingRateInfo(
+			List<Record> areaHbConfigRateLists) {
+		// TODO Auto-generated method stub
+		Integer batchSize = areaHbConfigRateLists.size();
+		int[] result = Db.batchUpdate("t_qcode_hb_config_rate",
+				areaHbConfigRateLists, batchSize);
+		if (result.length != batchSize) {
+			return (ResultMsg) new ResultMsg().set("msg", "connection fail")
+					.set("status", false);
+		}
+		return (ResultMsg) new ResultMsg().set("msg", "保存成功").set("status",
+				true);
+	}
+
+	@Override
+	public ResultMsg deleteAreaHbConfigInfo(Integer configId) {
+		// TODO Auto-generated method stub
+		Connection conn = null;
+		Record reocrd = Db.findFirst("select config_id from t_record where config_id = ?",configId);
+		if(reocrd != null){
+			return (ResultMsg) new ResultMsg().set("msg", "该配奖方案正在使用中,无法删除。")
+					.set("status", false); 
+		}
+		
+		try {
+			conn = DbKit.getConfig().getDataSource().getConnection();
+			DbKit.getConfig().setThreadLocalConnection(conn);
+			conn.setAutoCommit(false);// 自动提交变成false
+
+			String sql = "select id,config_id,name_,start_time,end_time from t_qcode_hb_config where config_id = ?";
+			String rateSql = "delete from t_qcode_hb_config_rate where time_id in (";
+			List<AreaHbConfig> AreaHbConfigRecords = AreaHbConfig.areaHbConfig
+					.find(sql,configId);
+			if (!AreaHbConfigRecords.isEmpty()) {
+				int acount = 0;
+				for (AreaHbConfig areaHbConfigRecord : AreaHbConfigRecords) {
+					if (areaHbConfigRecord != null) {
+						Integer id = areaHbConfigRecord.getInt("id") != null ? areaHbConfigRecord
+								.getInt("id") : 0;
+						if (id != 0) {
+							if (acount == 0) {
+								rateSql += + id;
+							} else {
+								rateSql += "," + id;
+							}
+							acount++;
+						}
+					}
+				}
+			}
+			String configSql = "delete from t_qcode_hb_config where config_id = ?";
+
+			Db.update(configSql, configId);
+
+			Db.update(rateSql+")");
+
+			conn.commit();
+
+			return (ResultMsg) new ResultMsg().set("msg", "删除成功").set("status",
+					true);
+		} catch (Exception ex) {
+			try {
+				if (null != conn)
+					conn.rollback();
+			} catch (SQLException e1) {
+				e1.printStackTrace();
+				return (ResultMsg) new ResultMsg().set("msg", "删除失败").set("status",
+						false);
+			}
+		} finally {
+			try {
+				if (null != conn) {
+					conn.close();
+				}
+			} catch (Exception e2) {
+				e2.printStackTrace();
+				return (ResultMsg) new ResultMsg().set("msg", "删除失败").set("status",
+						false);
+			} finally {
+				DbKit.getConfig().removeThreadLocalConnection();
+			}
+		}
+		return (ResultMsg) new ResultMsg().set("msg", "删除失败").set("status",
+						false);
+	}
+
+	@Override
+	public ResultMsg deleteAreaHbConfigRateInfo(Integer Id) {
+		// TODO Auto-generated method stub
+		AreaHbConfigRate.areaHbConfigRate.deleteById(Id);
+		return null;
+	}
+
+}

+ 150 - 0
src/main/java/com/qlm/service/impl/AuthServiceImpl.java

@@ -0,0 +1,150 @@
+package com.qlm.service.impl;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.Admin;
+import com.qlm.service.IAuthService;
+import com.qlm.tools.MenuTools;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMessage;
+import com.qlm.view.core.AdminView;
+
+/**
+ * 登陆权限管理
+ * 
+ * @author David
+ *
+ */
+public class AuthServiceImpl implements IAuthService {
+	
+	private static String T_NAME = "t_admin";
+
+	@Override
+	public AdminView login(AdminView adminView) {
+		String name = adminView.getUsername();
+		String pwd = adminView.getPassword();
+		String sql = "select * from "+T_NAME+" where username = ?  and password =?";
+		List<Admin> adminList = Admin.adminDao.find(sql,name,pwd);
+		if (adminList.size() == 1) {
+			AdminView adv = new AdminView();
+			adv.setLevel(adminList.get(0).getInt("level"));
+			adv.setId(adminList.get(0).getInt("id"));
+			adv.setUsername(adminList.get(0).getStr("username"));
+//			adv.setRoleId(adminList.get(0).getInt("role"));
+			String str = adminList.get(0).getStr("desc_");
+			adv.setCompanyName(str);
+			adv.setOriginId(adminList.get(0).getInt("id"));
+			if(adv.getLevel() == 3){
+				adv.setId(adminList.get(0).getInt("pid"));
+			}
+			Admin admin = adminList.get(0);
+			Integer hexiao = WxUtil.getInt("hexiao", admin,0);
+			adv.setHexiao(hexiao);
+			adv.setStatus(1);
+			return adv;
+		} else {
+			return null;
+		}
+	}
+
+	@Override
+	public boolean pwdCheck(String adminName, String pwd) {
+		String sql = "select * from "+T_NAME+" where username = ? and password = ?";
+		List<Admin> admin = Admin.adminDao.find(sql,adminName,pwd);
+		if (admin.size() == 0) {
+			return false;
+		} else {
+			return true;
+		}
+
+	}
+
+	@Override
+	public ResultMessage adminUpd(AdminView adminView) {
+		String sql = "select * from "+T_NAME+" where id = ? and password = ?"; 
+		List<Admin> admin = Admin.adminDao.find(sql,adminView.getId(),adminView.getOldPwd());
+		if (admin.size() == 0) {
+			return ResultMessage.setAllMessage(ResultMessage.StateDesc.FAIL.getValue(), "原密码输入有误,请重新填写!");
+		} else {
+			boolean flag = new Admin().findById(adminView.getId()).set("password", adminView.getPassword()).update();
+			if(flag){
+				return ResultMessage.setAllMessage(ResultMessage.StateDesc.SUCCESS.getValue(), "修改成功!");
+			}else{
+				return ResultMessage.setAllMessage(ResultMessage.StateDesc.FAIL.getValue(), "修改失败!");
+			}
+		}
+	}
+
+	@Override
+	public String getMenuByUserId(AdminView adminView, String contextPath) {
+		List<Record> resMenu = null;
+		int level = adminView.getLevel();
+		if(level == 1){
+			 resMenu = Db.find("select * from t_res where id in "
+					+ "(SELECT a.id FROM t_res a "
+					+ "join t_role_res b on b.resid = a.id "
+					+ "join t_role c on c.id = b.roleid where c.id = ? group by a.id) "
+					+ "order by index_ asc",1);
+		}else if(level == 2){
+			 int hexiao = adminView.getHexiao();
+			 if(hexiao == 0){
+				 resMenu = Db.find("select * from t_res where id in "
+							+ "(SELECT a.id FROM t_res a "
+							+ "join t_role_res b on b.resid = a.id "
+							+ "join t_role c on c.id = b.roleid where c.id = ? group by a.id) "
+							+ "order by index_ asc",2);
+			 }else{
+				 resMenu = Db.find("select * from t_res where id in "
+							+ "(SELECT a.id FROM t_res a "
+							+ "join t_role_res b on b.resid = a.id "
+							+ "join t_role c on c.id = b.roleid where c.id = ? group by a.id) "
+							+ "order by index_ asc",3);
+			 }
+			
+		}else{
+			 resMenu = Db.find("select * from t_res where id in "
+					+ "(SELECT a.id FROM t_res a "
+					+ "join t_role_res b on b.resid = a.id "
+					+ "join t_role c on c.id = b.roleid "
+					+ "join t_admin_role d on d.roleid = c.id "
+					+ "join t_admin e on e.id = d.userid where e.id = ? group by a.id) "
+					+ "order by index_ asc",adminView.getOriginId());
+		}
+
+
+		Map<Integer,Record> records = new LinkedHashMap<>();
+		for(Record res:resMenu){
+			if(res.getInt("pid") == null){
+				res.set("pid", 0);
+			}
+			records.put(res.getInt("id"), res);
+		}
+
+		Map<Integer,Record> root = new LinkedHashMap<>();
+		for(Map.Entry<Integer, Record> entry:records.entrySet()){
+			if(entry.getValue().getInt("pid") == 0){
+				root.put(entry.getKey(), entry.getValue());
+			}
+			if(entry.getValue().getInt("pid") != 0 && entry.getValue().getStr("res_url") == null){
+				records.get(entry.getKey()).set("hasChild", true);
+			}
+		}
+
+		for(Map.Entry<Integer, Record> entry:root.entrySet()){
+			for(Map.Entry<Integer, Record> subEntry:records.entrySet()){
+				if(entry.getKey().equals(subEntry.getValue().getInt("pid"))){
+					records.get(entry.getKey()).set("hasChild", true);
+					records.get(subEntry.getKey()).set("hasParent", true);
+
+				}
+			}
+		}
+
+		return MenuTools.jointMenu(records,0,contextPath,1);
+	}
+
+}

+ 69 - 0
src/main/java/com/qlm/service/impl/HBRateServiceImpl.java

@@ -0,0 +1,69 @@
+package com.qlm.service.impl;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.entity.HBRate;
+import com.qlm.rpc.CacheNotice;
+import com.qlm.service.IHBRateService;
+import com.qlm.tools.Common;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.ResultMsg;
+
+public class HBRateServiceImpl implements IHBRateService {
+	
+	private static final Logger logger = LoggerFactory.getLogger(HBRateServiceImpl.class);
+
+	@Override
+	public List<HBRate> getHBRateList(Integer type) {
+		return HBRate.dao.find("select * from t_hbrate where plan_id=? order by id",type);
+	}
+
+	@Override
+	public ResultMsg saveHbrate(String[] money_, String[] rate_, Integer planId,String planName,String [] prizeTypes ,int uid) {
+		ResultMsg rm = new ResultMsg();
+		
+		if(planId == null){
+			Record plan = new Record();
+			plan.set("plan_name", planName).set("is_del", 0)
+			.set("create_time", new Date()).set("update_time", new Date()).set("uid", uid);
+			Db.save("t_pj_plan", plan);
+			planId = WxUtil.getInt("id", plan);
+		}else{
+			String sql = "delete from t_hbrate where plan_id=?";
+			Db.update(sql,planId);
+			Db.update("update t_pj_plan set plan_name =? ,update_time = ? where id = ?",planName,new Date(),planId);
+		}
+		int len = money_.length;
+		for(int i=0;i<len;i++){
+			int money = 0;
+			String prizeType = prizeTypes[i];
+			if("1".equals(prizeType)){
+			    money = new BigDecimal(money_[i]).multiply(new BigDecimal(100)).intValue();
+			}else{
+				money = new BigDecimal(money_[i]).intValue();
+			}
+			new HBRate().set("uid", uid).set("money_", money).set("rate_", rate_[i]).set("plan_id", planId).set("prize_type", prizeTypes[i]).save();
+			
+			
+		}
+		rm.setStatus(true);
+		rm.setMsg("红包配置保存成功");
+		CacheNotice.updateScan();
+		return rm;
+	}
+	
+	/**
+	 * 发送请求给cache更新
+	 * @param type
+	 */
+
+}

+ 95 - 0
src/main/java/com/qlm/service/impl/IAdminServiceImpl.java

@@ -0,0 +1,95 @@
+package com.qlm.service.impl;
+
+import com.jfinal.aop.Before;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.service.IAdminService;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.tools.WxUtil;
+
+import java.util.List;
+
+/**
+ * @author nommpp
+ * @date 2020/3/2
+ */
+public class IAdminServiceImpl implements IAdminService {
+    @Override
+    public String getUsersList() {
+        List<Record> users = Db.find("select * from t_admin where status <> 3");
+        if(users != null){
+            for(Record user:users){
+                Record admin_role = Db.findFirst("select * from t_admin_role where userid = ? limit 1", JFinalUtil.getInt("id", user));
+                if(admin_role != null){
+                    Record role = Db.findById("t_role",JFinalUtil.getInt("roleid", admin_role));
+                    if(role != null){
+                        user.set("rolename", role.getStr("role_name"));
+                    }
+                }
+            }
+        }
+        return JsonKit.toJson(users);
+    }
+
+    @Before(Tx.class)
+    @Override
+    public boolean save(Record user) {
+        boolean result = Db.save("t_admin", user);
+        int insert = 0;
+        if(result){
+        	Integer id = WxUtil.getInt("id", user);
+            insert = Db.update("insert into t_admin_role (userid,roleid) values (?,?)",id,user.getInt("role"));
+        }
+        return insert > 0 ?true:false;
+    }
+
+    @Override
+    public boolean enableUser(Integer id) {
+        Record user = Db.findById("t_admin", id);
+        if(user == null){
+            return false;
+        }
+        user.set("status", 1);
+        return Db.update("t_admin", user);
+    }
+
+    @Override
+    public boolean disableUser(Integer id) {
+        Record user = Db.findById("t_admin", id);
+        if(user == null){
+            return false;
+        }
+        user.set("status", 0);
+        return Db.update("t_admin", user);
+    }
+
+    @Before(Tx.class)
+    @Override
+    public boolean updateUser(Record user) {
+        boolean result = Db.update("t_admin", user);
+        int insert = 0;
+        if(result){
+            insert = Db.update("update t_admin_role set roleid = ? where userid = ?",user.getInt("role"),user.getInt("id"));
+        }
+        return insert > 0 ?true:false;
+    }
+
+    @Before(Tx.class)
+    @Override
+    public boolean delUser(Integer id) {
+        Record user = Db.findById("t_admin", id);
+        if(user == null){
+            return false;
+        }
+        user.set("status", 3);
+        Db.update("delete from t_admin_role where userid = ?",id);
+        return Db.update("t_admin", user);
+    }
+
+    @Override
+    public Record getUserById(Integer id) {
+        return Db.findById("t_admin", id);
+    }
+}

+ 43 - 0
src/main/java/com/qlm/service/impl/OperatingServiceImpl.java

@@ -0,0 +1,43 @@
+package com.qlm.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.entity.Log;
+import com.qlm.service.IOperatingService;
+import com.qlm.tools.Common;
+import com.qlm.tools.DateUtils;
+import com.qlm.view.OperatingView;
+
+public class OperatingServiceImpl implements IOperatingService {
+
+	@Override
+	@Before(Tx.class)
+	public boolean OperatingRecord(String admin, String Content, String IPAddr) {
+		return new Log().set("id",null).set("operator", admin)
+				.set("content", Content).set("create_time", DateUtils.getNowdate())
+				.set("operate_ip", IPAddr).save();
+	}
+
+	@Override
+	public String OperatingRecordList(String aoData) {
+		String sql = "select operator,content,create_time,operate_ip from t_log ORDER BY create_time desc limit 1000";
+		List<Log> aorList = Log.logDao.find(sql);
+		List<Object> avList = new ArrayList<Object>();
+		int i = 1;
+		for (Log adminOperatingRecord : aorList) {
+			OperatingView 	aor = new OperatingView();
+			aor.setSeq(i+"");
+			aor.setName(adminOperatingRecord.getStr("operator"));
+			aor.setContent(adminOperatingRecord.getStr("content"));
+			aor.setIpAddr(adminOperatingRecord.getStr("operate_ip"));
+			aor.setOperationTime(DateUtils.formatString(
+					adminOperatingRecord.get("create_time"), DateUtils.PATTEN_HMS));
+			avList.add(aor);
+			i++;
+		}
+		return Common.dataTableSearch(aoData, avList);
+	}
+}

+ 24 - 0
src/main/java/com/qlm/service/impl/ProductServiceImpl.java

@@ -0,0 +1,24 @@
+package com.qlm.service.impl;
+
+import java.util.List;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.service.IProductService;
+import com.qlm.view.core.AdminView;
+
+public class ProductServiceImpl implements IProductService {
+
+	@Override
+	public List<Record> getProductInfoList(AdminView loginUser){
+		// TODO Auto-generated method stub
+		int uid = loginUser.getId();
+		return Db.find("select id,name_,type_,desc_ from t_product where uid = ?",uid);
+	}
+
+	@Override
+	public Record getProductInfoByType(Integer type) {
+		// TODO Auto-generated method stub
+		return Db.findFirst("select id,name_,type_,desc_,isUpload_ from t_product where type_ = ?",type);
+	}
+}

+ 341 - 0
src/main/java/com/qlm/service/impl/QrcodeAddServiceImpl.java

@@ -0,0 +1,341 @@
+package com.qlm.service.impl;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Enhancer;
+import com.jfinal.kit.PropKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.common.Define;
+import com.qlm.service.IProductService;
+import com.qlm.service.IQrcodeAddService;
+import com.qlm.tools.Common;
+import com.qlm.tools.DateUtils;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.tools.WxUtil;
+import com.qlm.tools.ZipCompressor;
+import com.qlm.view.core.AdminView;
+
+public class QrcodeAddServiceImpl implements IQrcodeAddService {
+
+	protected final static Logger logger = LoggerFactory
+			.getLogger(QrcodeAddServiceImpl.class);
+	private static Map<String, Integer> map = new HashMap<String, Integer>();
+	
+	static boolean isRunning = false;
+	
+	private IProductService productService = Enhancer.enhance(ProductServiceImpl.class);
+
+	/**
+	 * 在数据库中生成二维码编号,并将二维码链接写入TXT文件,并将本次产码文件生成ZIP包
+	 */
+	@Override
+	@Before(Tx.class)
+	public String getZipFilePath(String url, String code, Integer num,
+			String filePath, Integer addNum, String id,Integer type,String area,AdminView loginUser) {
+		if(isRunning){
+			return "有任务正在执行,请稍后";
+		}
+		logger.info("method getZipFilePath url=" + url);
+		logger.info("method getZipFilePath code=" + code);
+		logger.info("method getZipFilePath type=" + type);
+		logger.info("method getZipFilePath id=" + id);
+		logger.info("method getZipFilePath filePath=" + filePath);
+		logger.info("method getZipFilePath num=" + num);
+		logger.info("method getZipFilePath addNum=" + addNum);
+		logger.info("method getZipFilePath area=" + area);
+		// 判断传入参数是否正确
+		if (!Common.isEmptyString(url)) {
+			return "网络连接错误";
+		}
+		if (!Common.isEmptyString(code)) {
+			return "网络连接错误";
+		}
+		if (!Common.isEmptyString(id)) {
+			return "网络连接错误";
+		}
+		if (!Common.isEmptyString(filePath)) {
+			return "网络连接错误";
+		}
+		if (Common.isNullOrEmpty(addNum)) {
+			return "网络连接错误";
+		}
+		if (Common.isNullOrEmpty(type)) {
+			return "网络连接错误";
+		}
+		if (Common.isNullOrEmpty(num)) {
+			return "网络连接错误";
+		}
+		if (Common.isNullOrEmpty(area)) {
+			return "网络连接错误";
+		}
+		if (num > Define.ADD_QRCODE_MAX) {
+			return "产码数量超过500W";
+		}
+		if (num < Define.ADD_QRCODE_MIN) {
+			return "产码数量小于1";
+		}
+
+		try{
+			isRunning = true;
+			int uid = loginUser.getId();
+			code=code.toLowerCase();
+			String dbname = PropKit.use("config.properties").get("dbname");
+			
+			String sourceFilePath = null;// TXT文件路径
+			String tablename = "t_qcode_"+code;// 二维码表名
+			String hbtable = "t_qcode_hb_"+code;// 红包表名
+			String scantable = "t_qcode_scan_"+code;// 扫码表名
+//			String activatetable = "t_qrcode_activate_"+code;//激活码表不再使用(陈兆阳要求)
+			String createTime = DateUtils.getStringFullDate();// 产码时间
+			
+			String sql = "select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA='" + dbname + "' and TABLE_NAME= ? ";
+			String qrcodeSql = "create table "+tablename+" (`id` char(20) NOT NULL COMMENT '第一位是分表',`type_` int(11) NOT NULL DEFAULT '0',`config_id` int(11) DEFAULT NULL,`master_code` varchar(20) DEFAULT NULL,`active_time` datetime DEFAULT NULL COMMENT '激活时间',`num_` int(11),`area` varchar(255) DEFAULT NULL DEFAULT NULL,PRIMARY KEY (`id`),KEY `num_` (`num_`) USING BTREE) ENGINE=InnoDB DEFAULT CHARSET=utf8";
+			String hbSql = "create table "+hbtable+" (`id` char(20) NOT NULL,  `openid` varchar(64) DEFAULT NULL,  `send_time` datetime DEFAULT NULL COMMENT '首次扫码时间',  `amount` int(11) DEFAULT NULL,  `send_state` smallint(6) DEFAULT NULL,  `no_` varchar(50) DEFAULT NULL,`nick_name` varchar(100) DEFAULT NULL,`type_` int(11) DEFAULT NULL, PRIMARY KEY (`id`),UNIQUE KEY `no_` (`no_`) USING BTREE,KEY `send_time` (`send_time`) USING BTREE) ENGINE=InnoDB DEFAULT CHARSET=utf8";
+			String scanSql = "create table "+scantable+" (`id` char(20) NOT NULL,  `openid` varchar(64) DEFAULT NULL,  `scan_time` datetime DEFAULT NULL COMMENT '首次扫码时间',  `nick_name` varchar(255) DEFAULT NULL COMMENT '首次扫码人昵称',  `scan_count` int(11) DEFAULT NULL COMMENT '被扫次数',  `amount` int(11) DEFAULT NULL,  `type_` int(11) DEFAULT NULL,`head_pic` varchar(255) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8";
+//			String activateSql = "CREATE TABLE "+activatetable+" (  `id` char(16) NOT NULL,`config_id` int(11) DEFAULT NULL,  PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+			if( Db.queryLong(sql,tablename) <= 0){
+				Db.update(qrcodeSql);
+			}
+			if( Db.queryLong(sql,hbtable) <= 0){
+				Db.update(hbSql);
+			}
+			if( Db.queryLong(sql,scantable) <= 0){
+				Db.update(scanSql);
+			}
+//			if( Db.queryLong(sql,activatetable) <= 0){
+//				Db.update(activateSql);
+//			}
+			
+			
+			
+			String idSql = "select IFNULL(max(num_),0) from " +tablename;
+			long maxNum = Db.queryLong(idSql);
+			long startNum = maxNum;
+			int insertCount = 0;// 已生成二维码数量
+			put(map, id, insertCount);
+			
+			Record product = productService.getProductInfoByType(type);
+			//主码
+			String masterCode = getMasterCode();
+			Boolean isUpload = true;
+	
+			//qrCodeID
+			String status = "";
+			//添加产码记录
+			com.qlm.entity.Record r = new com.qlm.entity.Record();
+			r.set("prefix", code).set("id_begin", startNum+1).set("id_end", startNum+num).set("uid", uid)
+			.set("number", num).set("create_time", createTime).set("area", area).set("type_", type).save();
+			int recordid = WxUtil.getInt("id", r);
+			// 生成数量大于分包数量
+			long countNum = 0;
+			if (num > Define.ADD_QRCODE_SINGLE) {
+				
+			} else {// 生成数量小于分包数量
+				countNum = maxNum +1;
+				StringBuilder sb = new StringBuilder();
+				sb.append("insert into " + tablename +" (id,type_,num_,area,record_id,random_,uid) values ");
+				for (int k = 0; k < num - 1; k++) {// 拼接sql
+					String randomNumber = getRandomNumber(4);
+					status = getRandomString(code);
+					sb.append("('").append(status).append("',").append(type).append(",").append(countNum).append(",'").append(area).append("',"+recordid+",'"+randomNumber+"',"+uid+"),");
+					insertCount = k + 1;
+					put(map, id, insertCount);
+					countNum++;
+				}
+				String randomNumber = getRandomNumber(4);
+				status = getRandomString(code);
+				sb.append("('").append(status).append("',").append(type).append(",").append(countNum).append(",'").append(area).append("',"+recordid+",'"+randomNumber+"',"+uid+")");
+				Db.update(sb.toString());
+				System.out.println(sb);
+				insertCount = num;
+				put(map, id, insertCount);
+				sourceFilePath = getTxtPath(num, filePath, maxNum, tablename,code,
+						addNum, createTime, url ,type);
+			}
+			
+			
+			
+			
+			map.remove(id);
+			String productName = Db.queryStr("select name_ from t_product where type_ = ?",type);
+			return getFilePath(filePath, sourceFilePath,num,productName);
+		}catch (Exception e) {
+			e.printStackTrace();
+			isRunning = false;
+			logger.error("产码错误",e);
+		}finally{
+			isRunning = false;
+		}
+		return "网络连接错误";
+	}
+	  public static String getRandomNumber(int length) { //length��ʾ�����ַ����ij���
+		    String base = "0123456789";   
+		    Random random = new Random();   
+		    StringBuffer sb = new StringBuffer();   
+		    for (int i = 0; i < length; i++) {   
+		        int number = random.nextInt(base.length());   
+		        sb.append(base.charAt(number));   
+		    }  
+		    if(sb.length()!=4){
+		    	System.out.println(sb.length());
+		    }
+		    return sb.toString();   
+		 }  
+	private String getMasterCode(){
+		String date = DateUtils.getDateFormatStr(DateUtils.PATTEN_YMD_NO_SEPRATE);
+		String randomCode = getRandomStringForMasterCode(4);
+		String masterCode = date+randomCode;
+		Record record = Db.findById("t_master","master_code", masterCode);
+		if(record != null){
+			masterCode = getMasterCode();
+		}
+		return masterCode;
+	}
+	
+	public static String getRandomStringForMasterCode(int length){
+	    //定义一个字符串(A-Z,a-z,0-9)即62位;
+	    String str="zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
+	    //由Random生成随机数
+	        Random random=new Random();  
+	        StringBuffer sb=new StringBuffer();
+	        //长度为几就循环几次
+	        for(int i=0; i<length; ++i){
+	          //产生0-61的数字
+	          int number=random.nextInt(62);
+	          //将产生的数字通过length次承载到sb中
+	          sb.append(str.charAt(number));
+	        }
+	        //将承载的字符转换成字符串
+	        return sb.toString();
+	}
+
+	public String getFilePath(String filePath, String sourceFilePath,Integer count,String productName) {
+		if (sourceFilePath != null) {// 打包文件
+
+			String fileName = "二维码_"+productName+"_"+DateUtils.getDateFormatStr(DateUtils.PATTEN_YMD_NO_SEPRATE)+"_"+count;
+			File sourceFile = new File(sourceFilePath);
+			if (sourceFile.exists()) {
+				filePath = sourceFile.getParentFile().getAbsolutePath();
+			}
+			ZipCompressor zc = new ZipCompressor(filePath+".zip");
+			zc.compressExe(filePath);
+			// 下载时候使用,@后面的为下载的文件名称,前面的为服务器文件路径
+			String pathName = filePath + ".zip" + "@" + fileName;
+			return pathName;
+		}
+		return "产码失败";
+	}
+
+	/**
+	 * 将二维码链接写入TXT文件中,返回文件地址
+	 */
+	private String getTxtPath(int count, String filePath, long maxNum,
+			String tablename,String code, Integer addNum, String createTime, String url,Integer type ) {
+		// 查询新插入二维码集合
+		String sql1 = "select id,num_,random_ from " + tablename + " where num_ > " + maxNum+" order by num_ asc";
+		List<Record> idList = Db.find(sql1);
+		if (idList.size() > 0) {// 集合不为空,生成txt文件
+
+			// 文件路径为“://”+厂商名称+“//”+文件名称为产品名称_当前日期+"//"+生成数量.txt
+			if(type==0){
+				filePath = filePath + File.separator + "pg_"+createTime
+						+ File.separator;				
+			}else{
+				filePath = filePath + File.separator + "pg_"+createTime
+						+ File.separator;
+			}
+			filePath = filePath + (maxNum + 1) + "_" + (maxNum + count) + ".txt";
+			String s1 = new String();// 内容更新
+			try {
+				File f = new File(filePath);
+				if (!f.getParentFile().exists()) {
+					f.getParentFile().mkdirs();// 不存在则创建文件夹
+				}
+				if (!f.exists()) {
+					f.createNewFile();
+				}
+				BufferedWriter output = new BufferedWriter(new FileWriter(f,
+						true));
+				for (int j = 0; j < count; j++) {
+					String strId = JFinalUtil.getStr("id", idList.get(j)).toString();
+					String suffix =  JFinalUtil.getInt("num_", idList.get(j)).toString();
+					String random_ =  JFinalUtil.getStr("random_", idList.get(j)).toString();
+					if (addNum == 0) {// 判断是否生成编号
+						s1 = url + "/" + strId + "\r\n";
+					} else {
+						int length = 8 - suffix.length();
+						for (int k = 0; k < length; k++) {
+							suffix = "0" + suffix;
+						}
+						s1 = url + "/" + strId + "," + code.toLowerCase()+suffix +","+random_+"\r\n";
+					}
+					output.write(s1.toLowerCase());
+				}
+				output.close();
+				return filePath;
+			} catch (Exception e) {
+				logger.error("创建文件失败",e);
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * 获取产码数量
+	 */
+	@Override
+	public Integer getProgress(String id) {
+		if (!Common.isEmptyString(id)) {
+			return null;
+		}
+		Integer insertCount = map.get(id);
+		return insertCount;
+	}	
+
+	private synchronized void put(Map<String, Integer> map, String id,
+			Integer num) {
+		map.put(id, num);
+	}	
+
+	@Override
+	public List<String> getPropertiesUrl() {
+		List<String> urlList = new ArrayList<String>();
+		String str = PropKit.use("config.properties").get("url");
+		if(Common.isEmptyString(str)){//不为空,以“,”拆分
+			String[] urls = str.split(",");	
+			for(int i=0;i<urls.length;i++){
+				if(Common.isEmptyString(urls[i])){
+					urlList.add(urls[i]);					
+				}
+			}
+		}else{
+			logger.info("配置文件中url不存在");			
+		}
+		return urlList;
+	}
+
+	/**
+	 * 随机生成字符串
+	 * @param flg 分表明前缀(a,b,c,d,........z)
+	 * @return
+	 */
+	private static String getRandomString(String flg){
+	     String str = Common.getUUID();
+	     str = str.substring(0, Define.QRCODE_LENGTH);
+	     return  flg+str;
+	 }
+
+}

+ 191 - 0
src/main/java/com/qlm/service/impl/RecordServiceImpl.java

@@ -0,0 +1,191 @@
+package com.qlm.service.impl;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.aop.Before;
+import com.jfinal.aop.Enhancer;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.entity.Record;
+import com.qlm.service.IAreaHbConfigService;
+import com.qlm.service.IProductService;
+import com.qlm.service.IRecordService;
+import com.qlm.tools.Common;
+import com.qlm.tools.DateUtils;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.view.AreaHbConfigSelecView;
+import com.qlm.view.RecordView;
+import com.qlm.view.ResultMessage;
+import com.qlm.view.core.AdminView;
+
+public class RecordServiceImpl implements IRecordService {
+	
+	private static IAreaHbConfigService areaHbConfigService = Enhancer.enhance(AreaHbConfigServiceImpl.class);
+	
+	private IProductService productService = Enhancer.enhance(ProductServiceImpl.class);
+
+	@Override
+	public String getRecordList(String aoData,AdminView loginUser) {
+		int uid = loginUser.getId();
+		// 将参数转换成jsonArray类型
+				JSONArray jsonarray = JSONArray.parseArray(aoData);
+				JSONObject obj = (JSONObject) jsonarray.get(0);
+				// 传入的查询参数
+				String sSearch = obj.get("sSearch").toString();
+
+				StringBuilder sbSql = new StringBuilder(
+						"select r.*,p.desc_ from t_record r " +
+								"join t_product p on r.type_ = p.type_  where r.uid = "+uid+" ");
+				sbSql.append(" order by r.create_time desc");
+				// 分页查询
+				List<Record> areaList = Record.dao.find(sbSql.toString());
+
+				List<Object> aList = new ArrayList<>();
+
+				if (areaList != null) {
+					int index = 1;
+					for (Record r : areaList) {
+						RecordView av = new RecordView();
+						av.setSequenceNumber(index);
+						av.setId(r.getInt("id"));
+						Integer jihuo_ = JFinalUtil.getInt("jihuo_", r);
+						av.setJihuo_(jihuo_);
+						av.setNumber(r.getInt("number")==null?0:r.getInt("number"));
+						av.setId_begin(r.getInt("id_begin")==null?0:r.getInt("id_begin"));
+						av.setId_end(r.getInt("id_end")==null?0:r.getInt("id_end"));
+						av.setValid(r.getInt("valid")==null?0:r.getInt("valid"));
+						av.setValid_time(r.getDate("valid_time")==null?null:DateUtils.dateToString(r.getDate("valid_time"), DateUtils.PATTEN_HMS));
+						av.setCreate_time(r.getDate("create_time")==null?null:DateUtils.dateToString(r.getDate("create_time"), DateUtils.PATTEN_HMS));
+						av.setPrefix(r.getStr("prefix")==null?"":r.getStr("prefix").toUpperCase());
+						av.setArea(r.getStr("area"));
+						av.setConfig_id(r.getInt("config_id")==null?-1:r.getInt("config_id"));
+						av.setType_(r.getInt("type_")==null?-1:r.getInt("type_"));
+						/*
+						String typeName = "";
+						com.jfinal.plugin.activerecord.Record productRecord = productService.getProductInfoByType(av.getType_());
+						if(productRecord != null){
+							typeName = JFinalUtil.getStr("desc_", productRecord);
+						}
+						 */
+						av.setTypeName(r.getStr("desc_") == null?"":r.getStr("desc_"));
+						List<AreaHbConfigSelecView> selectViews = new ArrayList<>();
+
+						AreaHbConfigSelecView selectViewFrist = new AreaHbConfigSelecView();
+						selectViewFrist.setConfig_id(-1);
+						selectViewFrist.setName("主配置");
+						if(av.getConfig_id().equals(-1)){
+							selectViewFrist.setFlag("selected");
+						}else{
+							selectViewFrist.setFlag("");
+						}						
+						selectViews.add(selectViewFrist);
+						av.setSelectView(selectViews);
+						aList.add(av);
+						index++;
+					}
+				}
+
+		return Common.dataTableSearch(aoData, aList);
+	}
+	
+	private static List<com.jfinal.plugin.activerecord.Record> getSelectRecord(){
+		return areaHbConfigService.findAreaHbConfig();
+	}
+
+	@Override
+	@Before(Tx.class)
+	public ResultMessage setValid(Integer id, Integer valid,Integer config_id) {
+		if(!Common.isNullOrEmpty(id) && !Common.isNullOrEmpty(valid)&& !Common.isNullOrEmpty(config_id)){
+			if(valid == 0 || valid == 1){
+				Record r = Record.dao.findById(id);
+				r.set("valid", valid).set("valid_time", DateUtils.dateToString(DateUtils.PATTEN_HMS)).set("config_id", config_id).update();
+				String prefix = JFinalUtil.getStr("prefix", r);
+				Db.update("update t_qcode_"+prefix+" set config_id = ? where record_id = ?",config_id,id);
+				return new ResultMessage(1, "修改状态成功", null);
+			}
+		}
+		return new ResultMessage(0, "网络连接错误", null);
+	}
+
+	@Override
+	@Before(Tx.class)
+	public ResultMessage updateArea(Integer id, Integer config_id) {
+		// TODO Auto-generated method stub
+		if(!Common.isNullOrEmpty(id) && !Common.isNullOrEmpty(config_id)){
+			Record r = Record.dao.findById(id);
+			r.set("config_id", config_id).update();
+			String prefix = JFinalUtil.getStr("prefix", r);
+			Db.update("update t_qcode_"+prefix+" set config_id = ? where record_id = ?",config_id,id);
+			return new ResultMessage(1, "修改状态成功", null);			
+		}
+		return new ResultMessage(0, "网络连接错误", null);
+	}
+
+	@Override
+	@Before(Tx.class)
+	public ResultMessage activeCode(Record r) {
+		int idBegin = JFinalUtil.getInt("id_begin", r);
+		int idEnd = JFinalUtil.getInt("id_end", r);
+		String prefix = r.getStr("prefix");
+		String tableName = "t_qcode_"+prefix;
+		SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
+		String masterCode = sf.format(new Date());
+
+		int batchCount = 200000;
+		int totalCount = idEnd - idBegin + 1;
+
+		if(totalCount > batchCount) {
+			int count = totalCount / batchCount;
+			int residue = totalCount % batchCount;
+			int start = idBegin;
+			int len = start + batchCount;
+			for (int i = 0; i < count; i++) {
+				String sql = "select id,type_,config_id,master_code,active_time,num_ from t_qcode_"+prefix+" where num_ between "+ start+" and "+len;
+				List<com.jfinal.plugin.activerecord.Record> codeList = Db.find(sql);
+				StringBuilder sql2 = new StringBuilder("update t_qcode_").append(prefix)
+						.append(" set master_code ='").append(masterCode)
+						.append("',active_time = now()")
+						.append(" where id in ('");
+				for(com.jfinal.plugin.activerecord.Record record :codeList){
+					String qrcodeId = JFinalUtil.getStr("id", record);
+					sql2.append(qrcodeId).append("','");
+				}
+				String strSql = sql2.toString();
+				strSql = strSql.substring(0,strSql.length() - 2)+")";
+				Db.update(strSql);
+				start = len + 1;
+				len += batchCount;
+			}
+
+			if(residue > 0){
+				String sql = "select id,type_,config_id,master_code,active_time,num_ from t_qcode_"+prefix+" where num_ between "+ start+" and "+idEnd;
+				List<com.jfinal.plugin.activerecord.Record> codeList = Db.find(sql);
+				StringBuilder sql2 = new StringBuilder("update t_qcode_").append(prefix)
+						.append(" set master_code ='").append(masterCode)
+						.append("',active_time = now()")
+						.append(" where id in ('");
+				for(com.jfinal.plugin.activerecord.Record record :codeList){
+					String qrcodeId = JFinalUtil.getStr("id", record);
+					sql2.append(qrcodeId).append("','");
+				}
+				String strSql = sql2.toString();
+				strSql = strSql.substring(0,strSql.length() - 2)+")";
+				Db.update(strSql);
+			}
+		}
+		else{
+			Db.update("update "+tableName+" set master_code = ?,active_time = now() where num_>= "+idBegin+" and num_<="+idEnd,masterCode);
+		}
+		r.set("jihuo_", 1);
+
+		if(r.update()){
+			return new ResultMessage(1, "激活成功", null);
+		}
+		return new ResultMessage(0, "激活失败,批次表更新失败", null);
+	}
+}

+ 72 - 0
src/main/java/com/qlm/service/impl/ResServiceImpl.java

@@ -0,0 +1,72 @@
+package com.qlm.service.impl;
+
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.entity.Res;
+import com.qlm.service.IResService;
+import com.qlm.tools.JFinalUtil;
+
+public class ResServiceImpl implements IResService {
+
+	@Override
+	public String getResList() {
+		List<Record> resList = Db.find("select * from t_res");
+		return JsonKit.toJson(resList);
+	}
+
+	@Override
+	public String getMenuTree() {
+		return JsonKit.toJson(Db.find("select id,ifNull(pid,'0') as pId,res_name as name from t_res order by index_ asc"));
+	}
+
+	@Before(Tx.class)
+	@Override
+	public boolean del(Integer id) {
+		Db.update("delete from t_res where pid = ?",id);
+		boolean result = Db.deleteById("t_res", id);
+		
+		return result;
+	}
+
+	@Override
+	public Record getById(Integer id) {
+		Record res = Db.findById("t_res", id);
+		
+		//res.set("pid", getResNameByPid(res.getInt("pid")));
+		return res;
+	}
+
+	@Override
+	public String getResNameByPid(Integer pid) {
+		Record parent =  Db.findFirst("select * from t_res where id = ?",pid);
+		if(parent != null){
+			return parent.getStr("res_name");
+		}
+		return null;
+	}
+
+    @Override
+    public boolean add(Res res) {
+        if(res.save()){
+            Integer id = JFinalUtil.getInt("id", res);
+            Record admin = Db.findFirst("select * from t_admin_role r where r.userid = (select a.id from t_admin a where a.username='admin')");
+            if(admin != null){
+                Integer roleId = JFinalUtil.getInt("roleid", admin);
+                Record r = new Record();
+                r.set("roleid", roleId).set("resid", id);
+                if(Db.save("t_role_res", r)){
+                    return true;
+                }else{
+                    return false;
+                }
+            }
+        }
+        return false;
+    }
+
+}

+ 116 - 0
src/main/java/com/qlm/service/impl/RoleServiceImpl.java

@@ -0,0 +1,116 @@
+package com.qlm.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.jfinal.aop.Before;
+import com.jfinal.kit.JsonKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.activerecord.tx.Tx;
+import com.qlm.service.IRoleService;
+import com.qlm.tools.WxUtil;
+import com.qlm.view.core.AdminView;
+
+public class RoleServiceImpl implements IRoleService {
+
+	@Override
+	public String getRolesList(AdminView loginUser) {
+		if(loginUser.getLevel() == 2){
+			List<Record> roles = Db.find("select * from t_role where user_id = ?",loginUser.getId());
+			return JsonKit.toJson(roles);
+		}else{
+			List<Record> find = Db.find("select * from t_role where user_id is null");
+			return JsonKit.toJson(find);
+		}
+		
+	}
+
+	@Override
+	public boolean getRoleByName(String name) {
+		Record role = Db.findFirst("select * from t_role where role_name = ?",name);
+		if(role == null){
+			return true;
+		}else{
+			return false;
+		}
+	}
+
+	@Override
+	public boolean save(String roleName,AdminView loginUser) {
+		int id = 0;
+		Record findFirst = Db.findFirst("select max(id) id from t_role");
+		if(findFirst != null){
+			id = WxUtil.getInt("id", findFirst);
+		}
+		id ++;
+		int result = 0;
+		if(loginUser.getLevel() == 1){
+			 result = Db.update("insert into t_role (id,role_name,user_id) values (?,?,?)", id,roleName,loginUser.getId());
+		}else{
+			 result = Db.update("insert into t_role (id,role_name) values (?,?)", id,roleName);
+
+		}
+		if(result > 0){
+			return true;
+		}else{
+			return false;
+		}
+	}
+
+	@Override
+	public Record getRoleById(Integer id) {
+		return Db.findById("t_role", id);
+	}
+
+	@Override
+	public boolean updateRole(Record role) {
+		return Db.update("t_role", role);
+	}
+
+	@Override
+	public boolean delRole(Integer id) {
+		return Db.deleteById("t_role", id);
+	}
+
+	@Override
+	public List<Record> getAllRoles() {
+		return Db.find("select * from t_role");
+	}
+	
+	@Override
+	public String getAuthById(Integer roleId) {
+		List<Record> allRes = Db.find("SELECT id,ifNull(pid,'0') as pId,res_name as name FROM t_res order by index_ asc");
+		List<Record> roleRes = Db.find("SELECT a.id,a.res_name as name FROM t_res a	join t_role_res b on a.id = b.resid	join t_role c on c.id = b.roleid where c.id = ?",roleId);
+		List<Record> resultRes = new ArrayList<Record>(allRes.size());
+		if(roleRes != null && roleRes.size()>0){
+			for(Record res:allRes){
+				for(Record roRes:roleRes){
+					if(roRes.getStr("name").equals(res.getStr("name"))){
+						res.set("checked", true);
+						break;
+					}
+				}
+				resultRes.add(res);
+			}	
+		}else{
+			for(Record res:allRes){
+				res.set("checked", false);
+				resultRes.add(res);
+			}
+		}
+		return JsonKit.toJson(resultRes);
+	}
+
+	@Before(Tx.class)
+	@Override
+	public boolean saveRoleAuth(String[] auths, Integer roleId) {
+		int result = 0;
+		Db.update("delete from t_role_res where roleid = ?",roleId);
+		for(String auth:auths){
+			result += Db.update("insert into t_role_res (roleid,resid) values (?,?)",roleId,Integer.valueOf(auth));
+		}
+		return result > 0?true:false;
+	}
+
+}

+ 402 - 0
src/main/java/com/qlm/service/impl/SearchServiceImpl.java

@@ -0,0 +1,402 @@
+package com.qlm.service.impl;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.stream.Collectors;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.entity.ScanRecord;
+import com.qlm.entity.User;
+import com.qlm.service.ISearchService;
+import com.qlm.tools.CollectorsUtil;
+import com.qlm.tools.Common;
+import com.qlm.tools.DateUtils;
+import com.qlm.tools.JFinalUtil;
+import com.qlm.tools.LocalDateUtils;
+import com.qlm.view.ResultMsg;
+import com.qlm.view.ScanView;
+import com.qlm.view.UserListView;
+import com.qlm.view.core.AdminView;
+
+public class SearchServiceImpl implements ISearchService {
+
+	@Override
+	public ResultMsg searchByQrcode(String qrcode) {
+		ResultMsg rm = new ResultMsg();
+		if(Common.isEmptyString(qrcode)){
+			ScanView view = new ScanView();
+			ScanRecord scanrecord = ScanRecord.recordDao.findById(qrcode);
+			if(scanrecord == null){
+				rm.setStatus(true);
+				rm.setMsg("扫码记录为空");
+			}else{
+				String openid = JFinalUtil.getStr("openid", scanrecord);
+				if(Common.isEmptyString(openid)){
+					String sql = "select COUNT(openid) scancount from t_scanrecord where openid ='"+openid+"'";
+					String sql1 = "select IFNULL(sum(amount),0) totalamount from t_scanrecord where openid ='"+openid+"'";
+					long scancount = JFinalUtil.getInt("scancount", Db.findFirst(sql));
+					long totalamount = JFinalUtil.getInt("totalamount", Db.findFirst(sql1));
+					view.setScancount(scancount);
+					view.setTotalamount(totalamount);
+					User user = User.dao.findById(openid);					
+					if(user != null){
+						view.setUser(user);				
+					}
+				}
+				view.setScanrecord(scanrecord);
+				rm.setStatus(true);
+				rm.setObj(view);
+				rm.setMsg("扫码记录查询成功");
+			}
+		}else{
+			rm.setStatus(false);
+			rm.setMsg("网络连接错误");
+		}
+		return rm;
+	}
+
+	@Override
+	public ResultMsg searchByDateAndMoney(String date, String endTime,String type,String areaCode) {
+		ResultMsg rm = new ResultMsg();
+		if(Common.isEmptyString(date) && Common.isEmptyString(type)){
+			List<Record> list = new ArrayList<>();
+			String sql;
+			String sqlArea = "";
+			if(!"all".equals(areaCode)){
+                sqlArea += " and area = '"+areaCode+"' ";
+            }
+			//查询全部产品类型(C,D,E,F)
+			if("-1".equals(type)){
+			    sql = "select hb_,sum(hbc_) as hbc,sum(hbt_) as hbt from t_day_hb " +
+						"where day_ between '"+date+"' and '"+endTime+"'  and hb_>0 " +
+						"group by hb_";
+			}else{
+			    sql = "select hb_,sum(hbc_) as hbc,sum(hbt_) as hbt"
+						+" from t_day_hb_detail"
+						+" where day_ between '"+date+"' and '"+endTime+"'  and hb_>0 "
+						+" and type_ = "+type+""
+						+sqlArea
+						+" group by hb_";
+			}
+				
+			List<Record> result = Db.find(sql);
+
+			if(result.isEmpty()){
+				rm.setStatus(false);
+				rm.setMsg("没有统计数据");
+			}else{
+				result.sort((o1, o2) -> {
+					if (o1.getInt("hb_") > o2.getInt("hb_")) {
+						return -1;
+					} else if (o1.getInt("hb_") < o2.getInt("hb_")) {
+						return 1;
+					}
+					return 0;
+
+				});
+				//获得红包总和
+				BigDecimal sumAmount = result.stream()
+						.collect(CollectorsUtil.summingBigDecimal(r->r.getBigDecimal("hbt")));
+				for(Record record:result){
+					//获得红包个数
+					BigDecimal count = record.getBigDecimal("hbc");
+					//获得红包金额
+					BigDecimal amount = record.getBigDecimal("hbt");
+
+
+					Record r = new Record();
+					r.set("amount", record.getInt("hb_"));
+					r.set("count", count.intValue());
+					r.set("sum", amount.intValue());
+					list.add(r);
+				}
+
+				rm.setStatus(true);
+				rm.setMsg("查询成功");
+				rm.setObj(list);
+			}
+
+		}else{
+			rm.setStatus(false);
+			rm.setMsg("查询失败");
+		}
+		return rm;
+	}
+
+    @Override
+    public ResultMsg searchByCurrentAndMoney(String type, String areaCode) {
+        ResultMsg rm = new ResultMsg();
+        String startTime = LocalDateUtils.localToStr(LocalDateUtils.getDayStart(LocalDateTime.now()));
+        String endTime = LocalDateUtils.localToStr(LocalDateUtils.getDayEnd(LocalDateTime.now()));
+        if(Common.isEmptyString(type)){
+            List<Record> list = new ArrayList<>();
+            String sql;
+            String sqlArea = "";
+            if(!"all".equals(areaCode)){
+                sqlArea += " and area = '"+areaCode+"' ";
+            }
+            //查询全部产品类型(C,D,E,F)
+            if("-1".equals(type)){
+                sql = "select scan_time,amount,send_state from t_scanrecord  " +
+                        "where scan_time between '"+startTime+"' and '"+endTime+"'";
+            }else{
+                sql = "select scan_time,amount,send_state from t_scanrecord  " +
+                        "where scan_time between '"+startTime+"' and '"+endTime+"' " +
+                        " and type_ = "+type+" "+
+                        sqlArea;
+            }
+
+            List<Record> result = Db.find(sql);
+
+            if(result.isEmpty()){
+                rm.setStatus(false);
+                rm.setMsg("没有统计数据");
+            }else{
+
+                Map<Integer,List<Record>> map = result.parallelStream().filter(r->r.getInt("send_state")!=null)
+                        .collect(Collectors.groupingBy(r->r.getInt("amount"),Collectors.toList()));
+
+				TreeMap<Integer,List<Record>> amtTreeMap = new TreeMap<>(map);
+
+				//给map按照key排序
+				List<Map.Entry<Integer,List<Record>>> amountlist = new ArrayList<>(amtTreeMap.entrySet());
+
+				Collections.sort(amountlist, Comparator.comparing(Map.Entry::getKey));
+
+                for(Map.Entry<Integer,List<Record>> entry:amtTreeMap.entrySet()){
+                    List<Record> rd = entry.getValue();
+                    //获得红包个数
+                    Long count = rd.parallelStream().count();
+                    //获得红包金额
+                    Integer amount = rd.parallelStream()
+                            .collect(Collectors.summingInt(r->r.getInt("amount")));
+
+
+                    Record r = new Record();
+                    r.set("amount", entry.getKey());
+                    r.set("count", count.intValue());
+                    r.set("sum", amount.intValue());
+                    list.add(r);
+                }
+
+                rm.setStatus(true);
+                rm.setMsg("查询成功");
+                rm.setObj(list);
+            }
+
+        }else{
+            rm.setStatus(false);
+            rm.setMsg("查询失败");
+        }
+        return rm;
+    }
+
+    @Override
+	public List<Record> getAreaCodeByRecord(AdminView loginUser) {
+		// TODO Auto-generated method stub
+		List<Record> areaList = Db.find("SELECT area_name area FROM t_area where uid = ?",loginUser.getId());
+		return areaList;
+	}
+
+	@Override
+	public String searchByCountAndMoney(Integer counts, Integer dayCounts,
+			Integer money,String mobile,String aoData, AdminView loginUser) {
+		// TODO Auto-generated method stub		
+		List<Object> uList = new ArrayList<Object>();
+		
+		StringBuilder sbSql = new StringBuilder(
+				"select openid,head_pic,nick_name,sex,create_time,country,province,city,day_count,hb_amount,flag,mobile,total_count from t_user where openid is not null and uid = "+loginUser.getId()+" ");
+		List<Record> scanRecords = new ArrayList<Record>();
+		HashMap<String, Integer> dayCountMap= new HashMap<String, Integer>();
+		
+		if(mobile != null&& !"".equals(mobile.trim())){
+			sbSql.append(" and mobile like '%"+mobile+"%' ");
+			
+		}
+		if(counts != null&& counts>0){
+			sbSql.append(" and total_count >= "+counts+" " );
+			
+		}
+		
+		// 分页查询
+		List<Record> userList = Db.find(sbSql.toString());
+
+		if (userList != null) {
+ 			int index = 1;
+			for (Record r : userList) {
+				UserListView ulv = new UserListView();
+				ulv.setSequenceNumber(index);
+				ulv.setHead_pic(JFinalUtil.getStr("head_pic", r));
+				ulv.setNick_name(JFinalUtil.getStr("nick_name", r));
+				ulv.setSex(JFinalUtil.getStr("sex", r));
+				ulv.setCountry(JFinalUtil.getStr("country", r));
+				ulv.setProvince(JFinalUtil.getStr("province", r));
+				ulv.setCity(JFinalUtil.getStr("city", r));
+				ulv.setCreate_time(DateUtils.formatString(r.getDate("create_time"), DateUtils.PATTEN_YMDHMS));
+				if(scanRecords != null){
+					String openid = JFinalUtil.getStr("openid", r);
+					Integer day_count = dayCountMap.get(openid);
+					ulv.setDay_count(day_count);
+				}else{
+					ulv.setDay_count(r.getInt("day_count")==null?0:r.getInt("day_count"));
+				}
+				ulv.setTotal_count(r.getInt("total_count")==null?0:r.getInt("total_count"));
+				ulv.setHb_amount(r.getInt("hb_amount")==null?0:r.getInt("hb_amount"));
+				ulv.setMobile(JFinalUtil.getStr("mobile", r));
+				String state = "";
+				switch(r.getInt("flag")){
+				case 0:
+					state = "启用";
+					break;
+				case 1:
+					state = "禁用";
+					break;
+				}
+				ulv.setState(state);
+				uList.add(ulv);
+				index++;
+			}
+		}
+
+		return Common.dataTableSearch(aoData, uList);
+	}
+
+	@Override
+	public ResultMsg searchAreaHbBySendTimeAndType(String startDate,
+			String endDate, String type_) {
+		// TODO Auto-generated method stub
+		ResultMsg rm = new ResultMsg();
+
+//		List<Record> list = new ArrayList<Record>();
+//		Record sum = new Record();
+//		if(type_.equals("-1")){//查询全部产品类型(C,D,E,F)
+//			String sql1 = "SELECT qrcode_id,area,amount FROM `t_scanrecord` where send_state = 1 and send_time >='"+startDate+" 00:00:00' and send_time <= '"+endDate+" 23:59:59' ";
+//				list = Db.find(sql1);
+//			List<AreaHBView> viewList = new ArrayList<AreaHBView>();
+//			Map<String, Object> map = new HashMap<String, Object>();
+//			AreaHBView view = null;
+//			
+//			Map<String,Integer> areaAmount = list.parallelStream()
+//			                            .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.summingInt(r->((Record) r).getInt("amount"))));
+//			
+//			IntSummaryStatistics sum_amount = list.parallelStream().collect(Collectors.summarizingInt(r->r.getInt("amount")));
+//			
+//			for(Map.Entry<String, Integer> entry:areaAmount.entrySet()){
+//			    view = new AreaHBView();
+//                view.setAmount(entry.getValue());
+//                view.setArea(entry.getKey());
+//                viewList.add(view);
+//			}
+//			
+//			map.put("sum", sum_amount.getSum());
+//			map.put("list", viewList);
+//			rm.setStatus(true);
+//			rm.setMsg("查询成功");
+//			rm.setObj(map);
+//		}else{//分别查询(<C,E>,D,F)
+//			String sql1 = "SELECT qrcode_id,area,amount as amount FROM `t_scanrecord` where send_state = 1 and send_time >='"+startDate+" 00:00:00' and send_time <= '"+endDate+" 23:59:59' and type_ = "+type_+"";
+//			list = Db.find(sql1);
+//			List<AreaHBView> viewList = new ArrayList<>();
+//			Map<String, Object> map = new HashMap<String, Object>();
+//			AreaHBView view = null;
+//			Map<String,Integer> areaAmount = list.parallelStream()
+//                    .collect(Collectors.groupingBy(r->r.getStr("area"),Collectors.summingInt(r->r.getInt("amount"))));
+//			
+//			IntSummaryStatistics sum_amount = list.parallelStream().collect(Collectors.summarizingInt(r->r.getInt("amount")));
+//
+//            for(Map.Entry<String, Integer> entry:areaAmount.entrySet()){
+//                view = new AreaHBView();
+//                view.setAmount(entry.getValue());
+//                view.setArea(entry.getKey());
+//                viewList.add(view);
+//            }
+//			map.put("sum", sum_amount.getSum());
+//			map.put("list", viewList);
+//			rm.setStatus(true);
+//			rm.setMsg("查询成功");
+//			rm.setObj(map);
+//		}
+		return rm;
+	}
+
+	@Override
+	public List<Record> totla(String[] type, String startTime, String endTime, Integer group) {
+		String sql;
+		boolean flag = false;
+		StringBuilder builder = new StringBuilder("(");
+		for(String t:type){
+			builder.append(t).append(",");
+			if("-1".equals(t)){
+				flag = true;
+			}
+		}
+		builder.deleteCharAt(builder.length()-1);
+		builder.append(")");
+
+		if(flag){
+			sql = "select day_,sum(scan_) as scans,sum(hb_) as hbs,sum(hbc_) as hbcs " +
+					"from t_day_scan_hb t " +
+					"where day_ BETWEEN '"+startTime+"' and '"+endTime+"' " +
+					"group by day_";
+		}else{
+
+			sql = "select day_,sum(scan_) as scans,sum(hb_) as hbs,sum(hbc_) as hbcs " +
+					"from t_day_scan_hb t " +
+					"where day_ BETWEEN '"+startTime+"' and '"+endTime+"' " +
+					"and t.type_ in "+builder.toString()+" " +
+					"group by day_";
+		}
+
+		return Db.find(sql);
+	}
+
+    @Override
+    public List<Record> totla(String[] type) {
+        String sql;
+        boolean flag = false;
+        StringBuilder builder = new StringBuilder("(");
+        for(String t:type){
+            builder.append(t).append(",");
+            if("-1".equals(t)){
+                flag = true;
+            }
+        }
+        builder.deleteCharAt(builder.length()-1);
+        builder.append(")");
+        String startTime = LocalDateUtils.localToStr(LocalDateUtils.getDayStart(LocalDateTime.now()));
+        String endTime = LocalDateUtils.localToStr(LocalDateUtils.getDayEnd(LocalDateTime.now()));
+
+        if(flag){
+            sql = "select scan_time,amount,send_state from t_scanrecord  " +
+                    "where scan_time between '"+startTime+"' and '"+endTime+"'";
+        }else{
+
+            sql = "select scan_time,amount,send_state from t_scanrecord  " +
+                    "where scan_time between '"+startTime+"' and '"+endTime+"' "+
+                    "and type_ in "+builder.toString()+" ";
+        }
+
+        List<Record> rd = Db.find(sql);
+        String day = null;
+        Record result = new Record();
+        if(!rd.isEmpty()){
+            day = LocalDateUtils.dateToStr(rd.get(0).getDate("scan_time"));
+        }
+
+        Integer scans= rd.size();
+        Integer hbs = rd.parallelStream().filter(r->r.getInt("send_state")!=null).collect(Collectors.summingInt(r1->r1.getInt("amount")));
+        Long hbcs = rd.parallelStream().filter(r->r.getInt("send_state")!=null).count();
+        result.set("day_",day).set("scans",scans).set("hbs",hbs.intValue()).set("hbcs",hbcs.intValue());
+        List<Record> list = new ArrayList<>();
+        list.add(result);
+        return list;
+    }
+}

+ 153 - 0
src/main/java/com/qlm/service/impl/StatisticServiceImpl.java

@@ -0,0 +1,153 @@
+package com.qlm.service.impl;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.qlm.service.IStatisticService;
+import com.qlm.tools.DateUtils;
+import com.qlm.view.EchartDataView;
+
+public class StatisticServiceImpl implements IStatisticService {
+
+	@Override
+	public EchartDataView getEDV(String startDate, String endDate) {
+		EchartDataView edv = new EchartDataView();
+
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
+		Date sDate = new Date();
+		Date eDate = new Date();
+		try {
+			sDate = sdf.parse(startDate);
+			eDate = sdf.parse(endDate);
+		} catch (ParseException e) {
+			e.printStackTrace();
+		}
+
+		int days = getDays(sDate, eDate);
+		String[] dates = getXAxisData(days, sDate, eDate);
+
+		edv.setxAxisData(dates);// 完成x轴数据的添加
+		edv.setSeriesData(getSeriesByDate(days, dates, startDate, endDate));// 完成y轴数据的添加
+
+		return edv;
+	}
+
+	/**
+	 * 获取时间间隔天数
+	 * 
+	 * @param startDate
+	 * @param endDate
+	 * @return
+	 */
+	private int getDays(Date startDate, Date endDate) {
+		int day = (int) ((endDate.getTime() - startDate.getTime()) / (86400000) + 1);
+		return day;
+	}
+
+	/**
+	 * 获取x轴数据 时间数组
+	 * 
+	 * @param days
+	 * @param startDate
+	 * @param endDate
+	 * @return
+	 */
+	private String[] getXAxisData(int days, Date startDate, Date endDate) {
+
+		String[] dates = new String[days]; // 日期列表 x列数据
+
+		Date dateAdd = null;
+		for (int i = 0; i < days; i++) {
+			dateAdd = DateUtils.addDate(startDate, Calendar.DAY_OF_MONTH, i);
+			String dateStr = DateUtils.dateToString(dateAdd,
+					DateUtils.PATTEN_YMD);
+			dates[i] = dateStr;
+		}
+		return dates;
+	}
+
+	/**
+	 * 获取y轴数据 对应日期的扫码数据量
+	 * 
+	 * @param days
+	 * @param dates
+	 * @param sDate
+	 * @param eDate
+	 * @return
+	 */
+	private Integer[] getSeriesByDate(int days, String[] dates, String sDate,
+			String eDate) {
+		Integer[] counts = new Integer[days];
+		for (int i = 0; i < days; i++) {
+			counts[i] = 0;
+		}
+		String sql = " select DATE(scan_time) as scan_time,count(1) AS scanCount from t_scanrecord"
+				+ " where TO_DAYS(scan_time)>=TO_DAYS('"
+				+ sDate
+				+ "') and  TO_DAYS(scan_time)<=TO_DAYS('"
+				+ eDate
+				+ "')  GROUP BY TO_DAYS(scan_time);";
+		List<Record> list = Db.find(sql);
+		if (list.size() > 0) {
+			for (int i = 0; i < list.size(); i++) {
+				Record record = list.get(i);
+				Long scanCount = record.getLong("scanCount");
+				Date scanTime = record.getDate("scan_time");
+				String scan_time = DateUtils.dateToString(scanTime,
+						DateUtils.PATTEN_YMD);
+				for (int k = 0; k < days; k++) {
+					if (dates[k].equals(scan_time)) {
+						counts[k] = scanCount.intValue();
+						break;
+					}
+				}
+			}
+		}
+
+		return counts;
+	}
+
+	@Override
+	public EchartDataView getEDVOneDay() {
+		EchartDataView edv = new EchartDataView();
+		int hour = new Date().getHours();
+		String[] hours = new String[hour]; // 日期列表 x列数据
+		int start = 1;
+		for (int i = 0; i < hour; i++) {
+			hours[i] = start + i + "";
+		}
+		edv.setxAxisData(hours);// 完成x轴数据的添加
+		edv.setSeriesData(getSeriesByHour(hour, hours));// 完成y轴数据的添加
+
+		return edv;
+	}
+
+	private Integer[] getSeriesByHour(int hour, String[] hours) {
+		Integer[] counts = new Integer[hour];
+		for (int i = 0; i < hour; i++) {
+			counts[i] = 0;
+		}
+		String sql = "select HOUR(scan_time) as scan_time,count(*) AS scanCount from t_scanrecord "
+				+ "where DATE( NOW() ) = DATE(scan_time) and HOUR(scan_time)<="
+				+ hour + " GROUP BY HOUR(scan_time)";
+		List<Record> list = Db.find(sql);
+		for (int i = 0,len=list.size(); i< len; i++) {
+			Record record = list.get(i);
+			Long scanCount = record.getLong("scanCount");
+			Integer scanTime = record.getInt("scan_time");
+			for(int k=0;k<hour;k++){
+				if(hours[k].equals(scanTime+"")){
+					counts[k] = scanCount.intValue();
+					break;
+				}					
+			}
+		}
+		return counts;
+	}
+}

+ 0 - 0
src/main/java/com/qlm/service/impl/UnPayInfoService.java


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů