浏览代码

Merge branch 'master' of https://e.coding.net/chuanghaikeji/smartCampus/backend_code

夏文涛 2 年之前
父节点
当前提交
b8df552c1d
共有 36 个文件被更改,包括 3387 次插入40 次删除
  1. 5 0
      pom.xml
  2. 10 7
      src/main/java/com/template/api/SmartAuthorGroupControllerAPI.java
  3. 78 0
      src/main/java/com/template/api/WechatScanLoginControllerAPI.java
  4. 165 0
      src/main/java/com/template/common/utils/AesUtil.java
  5. 47 0
      src/main/java/com/template/common/utils/Base64Util.java
  6. 9 0
      src/main/java/com/template/common/utils/DataBliu.java
  7. 241 0
      src/main/java/com/template/common/utils/DateUtils.java
  8. 241 0
      src/main/java/com/template/common/utils/HttpClientUtils.java
  9. 99 0
      src/main/java/com/template/common/utils/PropertiesUtil.java
  10. 32 0
      src/main/java/com/template/common/utils/RandomTrackAlgorithm.java
  11. 617 0
      src/main/java/com/template/common/utils/TimeExchange2.java
  12. 41 0
      src/main/java/com/template/common/utils/TreeRecordsUtil.java
  13. 25 0
      src/main/java/com/template/common/utils/UUIDUtil.java
  14. 126 33
      src/main/java/com/template/controller/SmartAuthorGroupController.java
  15. 258 0
      src/main/java/com/template/controller/WechatScanLoginController.java
  16. 63 0
      src/main/java/com/template/mapper/WechatScanLoginMapper.java
  17. 14 0
      src/main/java/com/template/model/tongji/All.java
  18. 16 0
      src/main/java/com/template/model/tongji/DAll.java
  19. 41 0
      src/main/java/com/template/model/tongji/DayMeterDetail.java
  20. 53 0
      src/main/java/com/template/model/tongji/EnergyTj.java
  21. 50 0
      src/main/java/com/template/model/tongji/MeterMonthData.java
  22. 25 0
      src/main/java/com/template/model/tongji/MonthMeterDetail.java
  23. 24 0
      src/main/java/com/template/model/tongji/Tj.java
  24. 89 0
      src/main/java/com/template/model/weixin/AccessToken.java
  25. 36 0
      src/main/java/com/template/model/weixin/AuthorAndGroup.java
  26. 27 0
      src/main/java/com/template/model/weixin/AuthorAndGroup2.java
  27. 101 0
      src/main/java/com/template/model/weixin/AuthorListGroup.java
  28. 43 0
      src/main/java/com/template/model/weixin/HttpParame.java
  29. 65 0
      src/main/java/com/template/model/weixin/Result.java
  30. 135 0
      src/main/java/com/template/model/weixin/WechatUserUnionID.java
  31. 42 0
      src/main/java/com/template/model/weixin/userAuthor.java
  32. 4 0
      src/main/java/com/template/services/SmartAuthorGroupService.java
  33. 63 0
      src/main/java/com/template/services/WechatScanLoginService.java
  34. 10 0
      src/main/java/com/template/services/impl/SmartAuthorGroupServiceImpl.java
  35. 286 0
      src/main/java/com/template/services/impl/WechatScanLoginServiceImpl.java
  36. 206 0
      src/main/resources/mapper/template/WechatScanLoginMapper.xml

+ 5 - 0
pom.xml

@@ -212,6 +212,11 @@
             <version>5.4.3</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.github.pagehelper</groupId>
+            <artifactId>pagehelper-spring-boot-starter</artifactId>
+            <version>1.4.2</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 10 - 7
src/main/java/com/template/api/SmartAuthorGroupControllerAPI.java

@@ -1,5 +1,6 @@
 package com.template.api;
 
+import com.alibaba.fastjson.JSONObject;
 import com.template.model.pojo.SmartAuthorGroup;
 import com.template.model.result.CommonResult;
 import io.swagger.annotations.Api;
@@ -8,6 +9,8 @@ import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.text.ParseException;
+
 /**
  * @Author: binguo
  * @Date: 2023/3/30 星期四 17:28
@@ -17,19 +20,19 @@ import org.springframework.web.bind.annotation.*;
 @RequestMapping("/api/smartAuthorGroup")
 @Api(tags = {"SmartAuthorGroupControllerAPI"}, value = "权限组")
 public interface SmartAuthorGroupControllerAPI {
-    @PostMapping(value = "/insertSmartAuthorGroup")
+    @RequestMapping(value = "/insertSmartAuthorGroup")
     @ApiOperation(value = "添加权限组", notes = "添加权限组数据", httpMethod = "POST")
-    CommonResult insertSmartAuthorGroup(@Validated @RequestBody SmartAuthorGroup smartApply, BindingResult bindingResult);
+    CommonResult insertSmartAuthorGroup(@Validated @RequestBody JSONObject jsonObject, Integer samePower) throws ParseException;
 
-    @PostMapping(value = "/updateSmartAuthorGroupById")
+    @RequestMapping(value = "/updateSmartAuthorGroupById")
     @ApiOperation(value = "编辑权限组数据", notes = "编辑权限组数据", httpMethod = "POST")
-    CommonResult updateSmartAuthorGroupById(@Validated @RequestBody SmartAuthorGroup ra, BindingResult bindingResult);
+    CommonResult updateSmartAuthorGroupById(@Validated @RequestBody JSONObject jsonObject, Integer samePower) throws ParseException;
 
-    @GetMapping(value = "/queryPageSmartAuthorGroup")
+    @RequestMapping(value = "/queryPageSmartAuthorGroup")
     @ApiOperation(value = "权限组分页数据", notes = "权限组分页数据", httpMethod = "GET")
-    CommonResult queryPageSmartAuthorGroups(@RequestParam int currentPage, @RequestParam int pageCount, String name);
+    CommonResult queryAuthorListGroupList(@RequestParam Integer authorGroupId);
 
-    @GetMapping(value = "/deleteSmartAuthorGroupById")
+    @RequestMapping(value = "/deleteSmartAuthorGroupById")
     @ApiOperation(value = "根据ID删除指定权限组", notes = "根据ID删除指定权限组", httpMethod = "GET")
     CommonResult deleteSmartAuthorGroupById(@RequestParam int id);
 }

+ 78 - 0
src/main/java/com/template/api/WechatScanLoginControllerAPI.java

@@ -0,0 +1,78 @@
+package com.template.api;
+
+import com.template.model.result.CommonResult;
+import com.template.model.tongji.*;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import java.io.UnsupportedEncodingException;
+import java.text.ParseException;
+
+@RequestMapping("/api/wechat")
+@Api(tags = {"WechatScanLoginController"}, value = "扫码登录")
+public interface WechatScanLoginControllerAPI {
+
+    @RequestMapping(value = "/login")
+    @ApiOperation(value = "二维码登录")
+    public String login(Model model) throws UnsupportedEncodingException;
+
+    @RequestMapping(value = "/callback")
+    @ApiOperation(value = "登录回调")
+    public String callback(String code, String state) throws UnsupportedEncodingException;
+
+    @RequestMapping(value = "/bind")
+    @ApiOperation(value = "绑定微信", httpMethod = "GET")
+    public String bindUserMac(String cardNo) throws UnsupportedEncodingException;
+
+    @RequestMapping(value = "/bindcallback")
+    @ApiOperation(value = "绑定微信回调", httpMethod = "GET")
+    public String bindcallback(String code, String state, String cardNo) throws UnsupportedEncodingException;
+
+    @RequestMapping(value = "/insertMonthMeter")
+    @ResponseBody
+    public String insertMonthMeter(String month);
+
+    @RequestMapping(value = "/insertDayMeter")
+    @ResponseBody
+    public String insertDayMeter(String day);
+
+    @RequestMapping(value = "/getUserIdTj")
+    @ResponseBody
+    public CommonResult getUserIdTj();
+
+    @RequestMapping(value = "/getUserIdTjt")
+    @ResponseBody
+    public CommonResult getUserIdTjt();
+
+    @RequestMapping(value = "/getWaterTj")
+    @ResponseBody
+    public CommonResult getWaterTj();
+
+    @RequestMapping(value = "/getElcTj")
+    @ResponseBody
+    public CommonResult getElcTj();
+
+    @RequestMapping(value = "/getMonWater")
+    @ResponseBody
+    public CommonResult getMonWater() throws ParseException;
+
+    @RequestMapping(value = "/getMonElc")
+    @ResponseBody
+    public CommonResult getMonElc() throws ParseException;
+
+    @RequestMapping(value = "/getMeterMonthPage")
+    @ResponseBody
+    public CommonResult getMeterMonthPage(MeterMonthData meterMonthData,int currentPage, int pageCount);
+
+    @RequestMapping(value = "/getMeterDayPage")
+    @ResponseBody
+    public CommonResult getMeterDayPage(MeterMonthData meterMonthData,int currentPage, int pageCount);
+
+    @RequestMapping(value = "/getPosition")
+    @ResponseBody
+    public CommonResult getPosition();
+}

+ 165 - 0
src/main/java/com/template/common/utils/AesUtil.java

@@ -0,0 +1,165 @@
+package com.template.common.utils;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.UUID;
+
+/**
+ * <p>Title: AesUtil</p>
+ * <p>Description: AES加密解密</p>
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+public class AesUtil {
+
+	/**
+	 * 秘钥
+	 */
+	public static final String PASSWORD_SECRET_KEY = "EasyRailEveryday";
+	
+	/**
+	 * 初始向量
+	 */
+	public static final String INITIAL_VECTOR = "EasyRailEasyRail";
+	
+    /**
+     * 加密
+     * @param content 需要加密的内容
+     * @param password  加密密码
+     * @param keySize 密钥长度16,24,32(密码长度为24和32时需要将local_policy.jar/US_export_policy.jar两个jar包放到JRE目录%jre%/lib/security下)
+     * @return
+     */
+    public static byte[] encrypt(String content, String password, int keySize){
+    	try {                              
+        	//密钥长度不够用0补齐。
+    		SecretKeySpec key = new SecretKeySpec(ZeroPadding(password.getBytes(Base64Util.DEFAULT_CHARSET), keySize), "AES");
+    		//定义加密算法AES、算法模式ECB、补码方式PKCS5Padding
+            //Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+    		//定义加密算法AES 算法模式CBC、补码方式PKCS5Padding
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            //CBC模式模式下初始向量 不足16位用0补齐
+            IvParameterSpec iv = new IvParameterSpec(ZeroPadding(INITIAL_VECTOR.getBytes(Base64Util.DEFAULT_CHARSET),16));
+            byte[] byteContent = content.getBytes();  
+            //初始化加密
+            //ECB
+            //cipher.init(Cipher.ENCRYPT_MODE, key);
+            //CBC 
+			cipher.init(Cipher.ENCRYPT_MODE, key,iv);
+            byte[] result = cipher.doFinal(byteContent);
+            return result; 
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        } catch (NoSuchPaddingException e) {
+            e.printStackTrace();
+        } catch (InvalidKeyException e) {
+            e.printStackTrace();
+        } catch (IllegalBlockSizeException e) {
+            e.printStackTrace();
+        } catch (BadPaddingException e) {
+            e.printStackTrace();
+        } catch (InvalidAlgorithmParameterException e) {
+        	e.printStackTrace();
+        } catch (Exception e) {
+        	e.printStackTrace();
+        }
+        return null;
+    }
+    
+    /**解密
+     * @param content  待解密内容
+     * @param password 解密密钥
+     * @param keySize 密钥长度16,24,32(密码长度为24和32时需要将local_policy.jar/US_export_policy.jar两个jar包放到JRE目录%jre%/lib/security下)
+     * @return
+     */
+    public static String decrypt(byte[] content, String password, int keySize) {
+        try { 
+        	//密钥长度不够用0补齐。
+    		SecretKeySpec key = new SecretKeySpec(ZeroPadding(password.getBytes(), keySize), "AES");
+    		//定义加密算法AES、算法模式ECB、补码方式PKCS5Padding
+            //Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
+    		//定义加密算法AES 算法模式CBC、补码方式PKCS5Padding
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+            //CBC模式模式下初始向量 不足16位用0补齐
+            IvParameterSpec iv = new IvParameterSpec(ZeroPadding(INITIAL_VECTOR.getBytes(Base64Util.DEFAULT_CHARSET),16));
+            // 初始化解密
+            //ECB
+            //cipher.init(Cipher.DECRYPT_MODE, key);
+            //CBC
+            cipher.init(Cipher.DECRYPT_MODE, key,iv);
+            byte[] result = cipher.doFinal(content);
+            return new String(result,Base64Util.DEFAULT_CHARSET); 
+        } catch (NoSuchAlgorithmException e) {
+        	e.printStackTrace();
+        } catch (NoSuchPaddingException e) {
+        	e.printStackTrace();
+        } catch (InvalidKeyException e) {
+        	e.printStackTrace();
+        } catch (IllegalBlockSizeException e) {
+        	e.printStackTrace();
+        } catch (BadPaddingException e) {
+        	e.printStackTrace();
+        } catch (InvalidAlgorithmParameterException e){
+        	e.printStackTrace();
+        } catch (Exception e){
+        	e.printStackTrace();
+        }
+        return null;
+    }
+    
+    /**将二进制转换成16进制
+     * @param buf
+     * @return
+     */
+    public static String parseByte2HexStr(byte buf[]) {
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < buf.length; i++) {
+            String hex = Integer.toHexString(buf[i] & 0xFF);
+            if (hex.length() == 1) {
+                    hex = '0' + hex;
+            }
+            sb.append(hex.toUpperCase());
+        }
+        return sb.toString();
+    }
+    
+    /**将16进制转换为二进制
+     * @param hexStr
+     * @return
+     */
+    public static byte[] parseHexStr2Byte(String hexStr) {
+        if (hexStr.length() < 1){
+        	return null;
+        }
+        byte[] result = new byte[hexStr.length()/2];
+        for (int i = 0;i< hexStr.length()/2; i++) {
+            int high = Integer.parseInt(hexStr.substring(i*2, i*2+1), 16);
+            int low = Integer.parseInt(hexStr.substring(i*2+1, i*2+2), 16);
+            result[i] = (byte) (high * 16 + low);
+        }
+        return result;
+    }
+    
+    /**
+     * 字符达不到指定长度补0
+     * @param in 字符数组
+     * @param blockSize 长度
+     * @return
+     */
+    public static byte[] ZeroPadding(byte[] in,Integer blockSize){
+    	Integer copyLen = in.length;
+    	if (copyLen > blockSize) {
+			copyLen = blockSize;
+		}
+    	byte[] out = new byte[blockSize];
+    	System.arraycopy(in, 0, out, 0, copyLen);
+    	return out;
+    }
+
+}

+ 47 - 0
src/main/java/com/template/common/utils/Base64Util.java

@@ -0,0 +1,47 @@
+package com.template.common.utils;
+
+import org.apache.tomcat.util.codec.binary.Base64;
+
+import java.nio.charset.Charset;
+
+/**
+ * <p>Title: Base64Util</p>
+ * <p>Description: Base64Util工具类 --- 加密和解密</p>
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+public class Base64Util {
+	
+	public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
+	/**
+     * 解密
+     * @param str
+     * @return
+     */
+    public static String decodeStr(String str){
+        if (str == null) {
+			return null;
+		}
+		if (str.length() == 0) {
+			return "";
+		}
+		return new String(Base64.decodeBase64(new String(str).getBytes(DEFAULT_CHARSET)),DEFAULT_CHARSET).trim();
+    }
+
+    /**
+     * 加密
+     * 
+     * @param str
+     * @return
+     */
+    public static String encodeStr(String str){
+        if (str == null) {
+			return null;
+		}
+		if (str.length() == 0) {
+			return "";
+		}
+        return new String(Base64.encodeBase64Chunked(str.getBytes(DEFAULT_CHARSET)),DEFAULT_CHARSET).trim();
+    }
+
+}

+ 9 - 0
src/main/java/com/template/common/utils/DataBliu.java

@@ -0,0 +1,9 @@
+package com.template.common.utils;
+
+public class DataBliu {
+
+    public static double getTwo(double d1){
+        return (double) Math.round(d1 * 100) / 100;
+    }
+
+}

+ 241 - 0
src/main/java/com/template/common/utils/DateUtils.java

@@ -0,0 +1,241 @@
+package com.template.common.utils;
+
+import org.springframework.stereotype.Component;
+
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+/**
+ * <p>Title: DateUtils</p>
+ * <p>Description:日期工具类 </p>
+ * 
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+@Component // 加此注解是把此类实例化spring容器中
+public class DateUtils {
+
+	/**
+	 * 默认日期格式
+	 */
+	public static final String DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
+
+	/**
+	 * 如2018 0901 232211(年月日时分秒)
+	 * 
+	 * @return
+	 */
+	public String yyyyMMddHHmmss() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+		return sdf.format(Calendar.getInstance().getTime());
+	}
+
+	/**
+	 * 如20180901
+	 * 
+	 * @return
+	 */
+	public static String getYYYYMMdd() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+		return sdf.format(Calendar.getInstance().getTime());
+	}
+
+	/**
+	 * 如180901
+	 * @return
+	 */
+	public String getYYMMdd() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
+		return sdf.format(Calendar.getInstance().getTime());
+	}
+
+	/**
+	 * 如201809
+	 * @return
+	 */
+	public String getYYYYMM() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
+		return sdf.format(Calendar.getInstance().getTime());
+	}
+
+	/**
+	 * 如 2018/02/11
+	 * @return
+	 */
+	public String getQueryEndDate() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		return sdf.format(Calendar.getInstance().getTime());
+	}
+
+	/**
+	 * 如 2018/02/11
+	 * @return
+	 */
+	public String getQueryStartDate() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		Calendar cal = Calendar.getInstance();
+		cal.add(Calendar.DAY_OF_YEAR, -30);
+		return sdf.format(cal.getTime());
+	}
+
+	/**
+	 * 如 2018/02/11 12:30:00
+	 * @return
+	 */
+	public static String getQueryEndTime() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		return sdf.format(Calendar.getInstance().getTime());
+	}
+
+	/**
+	 * 如 2018/02/11
+	 * @return
+	 */
+	public String getQueryStartTime() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		Calendar cal = Calendar.getInstance();
+		cal.add(Calendar.DAY_OF_YEAR, -30);
+		return sdf.format(cal.getTime());
+	}
+
+	public String getQueryTwoAgoDate() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+		Calendar cal = Calendar.getInstance();
+		cal.add(Calendar.DAY_OF_YEAR, -2);
+		return sdf.format(cal.getTime());
+	}
+
+	/**
+	 * 字符串转换成日期
+	 * 
+	 * @param str 字符串
+	 * @param format 日期格式
+	 * @return 日期
+	 */
+	public static Date str2Date(String str, String format) {
+		if (null == str || "".equals(str)) {
+			return null;
+		}
+		// 如果没有指定字符串转换的格式,则用默认格式进行转换
+		if (null == format || "".equals(format)) {
+			format = DEFAULT_FORMAT;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(format);
+		Date date = null;
+		try {
+			date = sdf.parse(str);
+			return date;
+		} catch (ParseException e) {
+		}
+		return null;
+	}
+
+	/**
+	 * @param date 日期
+	 * @param format 日期格式
+	 * @return 字符串
+	 */
+	public static String date2Str(Date date, String format) {
+		if (null == date) {
+			return null;
+		}
+		SimpleDateFormat sdf = new SimpleDateFormat(format);
+		return sdf.format(date);
+	}
+
+	/**
+	 * 时间戳转换为字符串
+	 * @param time
+	 * @return
+	 */
+	public static String timestamp2Str(Timestamp time) {
+		Date date = new Date(time.getTime());
+		return date2Str(date, DEFAULT_FORMAT);
+	}
+
+	/**
+	 * 字符串转换为时间
+	 * @param str
+	 * @return
+	 */
+	public static Timestamp str2Timestamp(String str) {
+		Date date = str2Date(str, DEFAULT_FORMAT);
+		return new Timestamp(date.getTime());
+	}
+
+	/**
+	 * 字符串转换为时间
+	 * @param str
+	 * @return
+	 */
+	public static Timestamp str2Timestamp(String str, String formatStr) {
+		if (null == str) {
+			return null;
+		}
+		Date date = str2Date(str, formatStr);
+		return new Timestamp(date.getTime());
+	}
+
+	/**
+	 * 获取某年第一天日期
+	 * @param year 年份
+	 * @return Date
+	 */
+	public static Date getYearFirst(int year) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.clear();
+		calendar.set(Calendar.YEAR, year);
+		Date currYearFirst = calendar.getTime();
+		return currYearFirst;
+	}
+
+	/**
+	 * 获取某年最后一天日期
+	 * @param year  年份
+	 * @return Date
+	 */
+	public static Date getYearLast(int year) {
+		Calendar calendar = Calendar.getInstance();
+		calendar.clear();
+		calendar.set(Calendar.YEAR, year);
+		calendar.roll(Calendar.DAY_OF_YEAR, -1);
+		Date currYearLast = calendar.getTime();
+
+		return currYearLast;
+	}
+
+	@SuppressWarnings("static-access")
+	public static Date getnextLast(String datetime, int year) {
+		Calendar calendar = new GregorianCalendar();
+		Date date = null;
+		if (datetime.length() > 7) {
+			date = str2Date(datetime, "yyyy-MM-dd");
+		} else {
+			date = str2Date(datetime, "yyyy-MM");
+		}
+		calendar.setTime(date);
+		calendar.add(calendar.YEAR, year);// 把日期往后增加一年.整数往后推,负数往前移动
+		date = calendar.getTime();
+		return date;
+
+	}
+
+	public static String getrightDate(String datetime, int year) {
+		String date = "";
+		String years = datetime.substring(0, 4);
+		String dates = datetime.substring(4, datetime.length());
+		Integer s = new Integer(years) + year;
+		date = s + dates;
+		return date;
+	}
+
+	public static void main(String[] args) {
+		System.out.println(getrightDate("2018-09", 4));
+		System.out.println(date2Str(getnextLast("2018-09", 4), "yyyy-MM"));
+	}
+
+}

+ 241 - 0
src/main/java/com/template/common/utils/HttpClientUtils.java

@@ -0,0 +1,241 @@
+package com.template.common.utils;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.ssl.DefaultHostnameVerifier;
+import org.apache.http.conn.util.PublicSuffixMatcher;
+import org.apache.http.conn.util.PublicSuffixMatcherLoader;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>Title: HttpClientUtils</p>
+ * <p>Description: httpClient 工具类</p>
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+public class HttpClientUtils {
+	
+	/**
+	 * 默认参数设置
+	 * setConnectTimeout:设置连接超时时间,单位毫秒。
+	 * setConnectionRequestTimeout:设置从connect Manager获取Connection 超时时间,单位毫秒。
+	 * setSocketTimeout:请求获取数据的超时时间,单位毫秒。访问一个接口,多少时间内无法返回数据,就直接放弃此次调用。 暂时定义15分钟
+	 */
+	private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(600000).setConnectTimeout(600000).setConnectionRequestTimeout(600000).build();
+	
+	/**
+	 * 静态内部类---作用:单例产生类的实例
+	 * @author Administrator
+	 *
+	 */
+	private static class LazyHolder {    
+       private static final HttpClientUtils INSTANCE = new HttpClientUtils();    
+       
+    }  
+	private HttpClientUtils(){}
+	public static HttpClientUtils getInstance(){
+		return LazyHolder.INSTANCE;    
+	}
+	
+	/**
+	 * 发送 post请求
+	 * @param httpUrl 地址
+	 */
+	public String sendHttpPost(String httpUrl) {
+		HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost  
+		return sendHttpPost(httpPost);
+	}
+	
+	/**
+	 * 发送 post请求
+	 * @param httpUrl 地址
+	 * @param params 参数(格式:key1=value1&key2=value2)
+	 */
+	public String sendHttpPost(String httpUrl, String params) {
+		HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost  
+		try {
+			//设置参数
+			StringEntity stringEntity = new StringEntity(params, "UTF-8");
+			stringEntity.setContentType("application/x-www-form-urlencoded");
+			httpPost.setEntity(stringEntity);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return sendHttpPost(httpPost);
+	}
+	
+	/**
+	 * 发送 post请求
+	 * @param httpUrl 地址
+	 * @param maps 参数
+	 */
+	public String sendHttpPost(String httpUrl, Map<String, String> maps) {
+		HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost  
+		// 创建参数队列  
+		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+		for (String key : maps.keySet()) {
+			nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));
+		}
+		try {
+			httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return sendHttpPost(httpPost);
+	}
+	
+	/**
+	 * 发送Post请求
+	 * @param httpPost
+	 * @return
+	 */
+	private String sendHttpPost(HttpPost httpPost) {
+		CloseableHttpClient httpClient = null;
+		CloseableHttpResponse response = null;
+		HttpEntity entity = null;
+		String responseContent = null;
+		try {
+			// 创建默认的httpClient实例
+			httpClient = HttpClients.createDefault();
+			httpPost.setConfig(requestConfig);
+			// 执行请求
+			long execStart = System.currentTimeMillis();
+			response = httpClient.execute(httpPost);
+			long execEnd = System.currentTimeMillis();
+			System.out.println("=================执行post请求耗时:"+(execEnd-execStart)+"ms");
+			long getStart = System.currentTimeMillis();
+			entity = response.getEntity();
+			responseContent = EntityUtils.toString(entity, "UTF-8");
+			long getEnd = System.currentTimeMillis();
+			System.out.println("=================获取响应结果耗时:"+(getEnd-getStart)+"ms");
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭连接,释放资源
+				if (response != null) {
+					response.close();
+				}
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return responseContent;
+	}
+
+	/**
+	 * 发送 get请求
+	 * @param httpUrl
+	 */
+	public String sendHttpGet(String httpUrl) {
+		HttpGet httpGet = new HttpGet(httpUrl);// 创建get请求
+		return sendHttpGet(httpGet);
+	}
+	
+	/**
+	 * 发送 get请求Https
+	 * @param httpUrl
+	 */
+	public String sendHttpsGet(String httpUrl) {
+		HttpGet httpGet = new HttpGet(httpUrl);// 创建get请求
+		return sendHttpsGet(httpGet);
+	}
+	
+	/**
+	 * 发送Get请求
+	 * @param httpPost
+	 * @return
+	 */
+	private String sendHttpGet(HttpGet httpGet) {
+		CloseableHttpClient httpClient = null;
+		CloseableHttpResponse response = null;
+		HttpEntity entity = null;
+		String responseContent = null;
+		try {
+			// 创建默认的httpClient实例.
+
+			
+			httpClient = HttpClients.createDefault();
+
+			httpGet.setConfig(requestConfig);
+			// 执行请求
+			response = httpClient.execute(httpGet);
+			entity = response.getEntity();
+			responseContent = EntityUtils.toString(entity, "UTF-8");
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭连接,释放资源
+				if (response != null) {
+					response.close();
+				}
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return responseContent;
+	}
+	
+	/**
+	 * 发送Get请求Https
+	 * @param httpPost
+	 * @return
+	 */
+	private String sendHttpsGet(HttpGet httpGet) {
+		CloseableHttpClient httpClient = null;
+		CloseableHttpResponse response = null;
+		HttpEntity entity = null;
+		String responseContent = null;
+		try {
+			// 创建默认的httpClient实例.
+			PublicSuffixMatcher publicSuffixMatcher = PublicSuffixMatcherLoader.load(new URL(httpGet.getURI().toString()));
+			DefaultHostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(publicSuffixMatcher);
+			httpClient = HttpClients.custom().setSSLHostnameVerifier(hostnameVerifier).build();
+			httpGet.setConfig(requestConfig);
+			// 执行请求
+			response = httpClient.execute(httpGet);
+			entity = response.getEntity();
+			responseContent = EntityUtils.toString(entity, "UTF-8");
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			try {
+				// 关闭连接,释放资源
+				if (response != null) {
+					response.close();
+				}
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return responseContent;
+	}
+	
+	
+	
+}

+ 99 - 0
src/main/java/com/template/common/utils/PropertiesUtil.java

@@ -0,0 +1,99 @@
+package com.template.common.utils;
+
+import java.io.*;
+import java.net.URI;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * <p>Title: PropertiesUtil</p>
+ * <p>Description: properties资源文件解析工具</p>
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+public class PropertiesUtil {
+
+	private static Properties props = null;
+	private static URI uri;
+	private static String fileName = "/application.properties";
+	
+	private static InputStream in = null;
+
+	static {
+		try {
+			props = new Properties();
+			InputStream fis = PropertiesUtil.class.getResourceAsStream(fileName);
+			props.load(fis);
+			uri = PropertiesUtil.class.getResource(fileName).toURI();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * 获取某个属性
+	 */
+	public static String getProperty(String key) {
+		try {
+			props.load(PropertiesUtil.class.getResourceAsStream(fileName));
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return props.getProperty(key);
+	}
+
+	/**
+	 * 获取所有属性,返回一个map,不常用 可以试试props.putAll(t)
+	 */
+	@SuppressWarnings("rawtypes")
+	public static Map<String, String> getAllProperty() {
+		Map<String, String> map = new HashMap<String, String>();
+		Enumeration enu = props.propertyNames();
+		while (enu.hasMoreElements()) {
+			String key = (String) enu.nextElement();
+			String value = props.getProperty(key);
+			map.put(key, value);
+		}
+		return map;
+	}
+
+	/**
+	 * 在控制台上打印出所有属性,调试时用。
+	 */
+	public static void printProperties() {
+		props.list(System.out);
+	}
+
+	/**
+	 * 写入properties信息
+	 */
+	public static void writeProperties(String key, String value) {
+		try {
+			OutputStream fos = new FileOutputStream(new File(uri));
+			props.setProperty(key, value);
+			// 将此 Properties 表中的属性列表(键和元素对)写入输出流
+			props.store(fos, "『comments』Update key:" + key);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+	
+	/**
+	 * 取默认key的value
+	 * */
+	public static String getValue(String key){
+		String value = null;
+		props = new Properties();
+		in = PropertiesUtil.class.getResourceAsStream(fileName);
+		try {
+			props.load(in);
+		} catch (IOException e) {
+//			e.printStackTrace();
+		}
+		value = (String) props.get(key);
+		return value;
+	}
+
+}

+ 32 - 0
src/main/java/com/template/common/utils/RandomTrackAlgorithm.java

@@ -0,0 +1,32 @@
+package com.template.common.utils;
+
+import com.alibaba.fastjson.JSONObject;
+
+import java.math.BigDecimal;
+import java.util.*;
+
+public class RandomTrackAlgorithm {
+
+    public static BigDecimal makeRandom(float max, float min, int scale){
+        BigDecimal cha = new BigDecimal(Math.random() * (max-min) + min);
+        return cha.setScale(scale,BigDecimal.ROUND_HALF_UP);//保留 scale 位小数,并四舍五入
+    }
+
+    public static List<List<BigDecimal>> getPosition(){
+        List<List<BigDecimal>> all = new ArrayList<>();
+        // 生成随机坐标点
+        BigDecimal x = null;
+        BigDecimal y = null;
+        for (int i = 0; i < 10; i++) {
+            List<BigDecimal> list = new LinkedList<>();
+            // 114.449557,28.109357
+            x = makeRandom(0.001f,0.000001f,6).add(BigDecimal.valueOf(114.449557));
+            y = makeRandom(0.001f,0.000001f,6).add(BigDecimal.valueOf(28.109357));
+            list.add(x);
+            list.add(y);
+            all.add(list);
+        }
+        return all;
+    }
+
+}

+ 617 - 0
src/main/java/com/template/common/utils/TimeExchange2.java

@@ -0,0 +1,617 @@
+package com.template.common.utils;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * 时间转化工具 date转为时间戳 时间戳转date 互相与String的转换
+ * 所有出现的String time 格式都必须为(yyyy-MM-dd HH:mm:ss),否则出错
+ * @author 赵仁杰
+ *
+ */
+public class TimeExchange2 {
+
+    /**
+     * String(yyyy-MM-dd HH:mm:ss) 转 Date
+     *
+     * @param time
+     * @return
+     * @throws ParseException
+     */
+    // String date = "2010/05/04 12:34:23";
+    public static Date StringToDate(String time) throws ParseException {
+
+        Date date = new Date();
+        // 注意format的格式要与日期String的格式相匹配
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            date = dateFormat.parse(time);
+            System.out.println(date.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return date;
+    }
+
+    public static Date StringToDate2(String time) throws ParseException {
+
+        Date date = new Date();
+        // 注意format的格式要与日期String的格式相匹配
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            date = dateFormat.parse(time);
+            System.out.println(date.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return date;
+    }
+
+    /**
+     * String(yyyy-MM-dd HH:mm:ss) 转 Date
+     *
+     * @param time
+     * @return
+     * @throws ParseException
+     */
+    // String date = "2010/05/04 12:34:23";
+    public static Date StringToDate(String time, String formatStr) throws ParseException {
+
+        Date date = new Date();
+        // 注意format的格式要与日期String的格式相匹配
+        DateFormat dateFormat = new SimpleDateFormat(formatStr);
+        try {
+            date = dateFormat.parse(time);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return date;
+    }
+
+
+    /**
+     * Date转为String(yyyy-MM-dd HH:mm:ss)
+     *
+     * @param time
+     * @return
+     */
+    public static String DateToString(Date time) {
+        String dateStr = "";
+        Date date = new Date();
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH/mm/ss");
+        try {
+            dateStr = dateFormat.format(time);
+            System.out.println(dateStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return dateStr;
+    }
+
+    public static String ToSimpleMonth(Date time) {
+        String dateStr = "";
+        DateFormat dateFormat = new SimpleDateFormat("M");
+        try {
+            dateStr = dateFormat.format(time);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return dateStr;
+    }
+
+    /**
+     * String(yyyy-MM-dd HH:mm:ss)转10位时间戳
+     * @param time
+     * @return
+     */
+    public static Integer StringToTimestamp(String time){
+
+        int times = 0;
+        try {
+            times = (int) ((Timestamp.valueOf(time).getTime())/1000);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        if(times==0){
+            System.out.println("String转10位时间戳失败");
+        }
+        return times;
+
+    }
+    /**
+     * 10位int型的时间戳转换为String(yyyy-MM-dd HH:mm:ss)
+     * @param time
+     * @return
+     */
+    public static String timestampToString(Integer time){
+        //int转long时,先进行转型再进行计算,否则会是计算结束后在转型
+        long temp = (long)time*1000;
+        Timestamp ts = new Timestamp(temp);
+        String tsStr = "";
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            //方法一
+            tsStr = dateFormat.format(ts);
+            System.out.println(tsStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return tsStr;
+    }
+    /**
+     * 10位时间戳转Date
+     * @param time
+     * @return
+     */
+    public static Date TimestampToDate(Integer time){
+        long temp = (long)time*1000;
+        Timestamp ts = new Timestamp(temp);
+        Date date = new Date();
+        try {
+            date = ts;
+            //System.out.println(date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return date;
+    }
+    /**
+     * Date类型转换为10位时间戳
+     * @param time
+     * @return
+     */
+    public static Integer DateToTimestamp(Date time){
+        Timestamp ts = new Timestamp(time.getTime());
+
+        return (int) ((ts.getTime())/1000);
+    }
+
+    // 当前时间减1小时
+    public static String TimeDesH(String time) throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(time));
+        nowTime2.add(Calendar.HOUR, -1);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 最近两天
+    public static String getLastTwo() throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(getTime()));
+        nowTime2.add(Calendar.DATE, -2);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 当前时间加2分钟
+    public static String TimeRangeI10(String time,int m) throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(time));
+        nowTime2.add(Calendar.SECOND, m);//10分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 当前时间加多少分钟
+    public static String TimeRangeM(String time,int m) throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate2(time));
+        nowTime2.add(Calendar.MINUTE, m);//10分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+
+    // 当前时间减5分钟
+    public static String TimeRangeD(String time) throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(time));
+        nowTime2.add(Calendar.MINUTE, -300);//5分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 获取当前日期
+    public static String getDateStr(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd");
+        return sp.format(new Date());
+    }
+
+    // 获取当前日期
+    public static String getDate(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sp.format(new Date());
+    }
+
+    // 获取前天
+    public static String getQianDay() throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(getTime()));
+        nowTime2.add(Calendar.DATE, -5);//5分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 获取明天
+    public static String getTomorrow() throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(getTime()));
+        nowTime2.add(Calendar.DATE, 1);//5分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    // 获取昨天
+    public static String getYesturday()  {
+        try {
+            Calendar nowTime2 = Calendar.getInstance();
+            nowTime2.setTime(StringToDate(getTime()));
+            nowTime2.add(Calendar.DATE, -1);
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            return simpleDateFormat.format(nowTime2.getTime());
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    // 获取最近7个月
+    public static List<String> getLastSevenMonth() throws ParseException {
+        List<String> ls = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
+        for (int i = -6; i <= 0; i++) {
+            Calendar nowTime2 = Calendar.getInstance();
+            nowTime2.setTime(StringToDate(getTime()));
+            nowTime2.add(Calendar.MONTH, i);//5分钟前的时间
+            ls.add(simpleDateFormat.format(nowTime2.getTime()));
+        }
+        return ls;
+    }
+
+    public static String getTomorrowTime() throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(getTime()));
+        nowTime2.add(Calendar.DATE, 1);//5分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    public static String getWeek(String sdate) throws ParseException {
+        // 再转换为时间
+        Date date = StringToDate(sdate,"yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.setTime(date);
+        // int hour=c.get(Calendar.DAY_OF_WEEK);
+        // hour中存的就是星期几了,其范围 1~7
+        // 1=星期日 7=星期六,其他类推
+        return new SimpleDateFormat("EEEE").format(c.getTime());
+    }
+
+    // 今天星期几
+    public static String getWeek() throws ParseException {
+        String[] weeks = {"7","1","2","3","4","5","6"};
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(StringToDate(getTime()));
+        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
+        if(week_index<0){
+            week_index = 0;
+        }
+        return weeks[week_index];
+    }
+
+    // 明天星期几
+    public static String getTomorrowWeek() throws ParseException {
+        String[] weeks = {"7","1","2","3","4","5","6"};
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(StringToDate(getTomorrowTime()));
+        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
+        if(week_index<0){
+            week_index = 0;
+        }
+        return weeks[week_index];
+    }
+
+    // 获取当前时间
+    public static String getTime(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sp.format(new Date());
+    }
+
+    public static String getOnlyMM(){
+        SimpleDateFormat sp = new SimpleDateFormat("HH:mm");
+        return sp.format(new Date());
+    }
+
+    public static String getOnlyDesMM() throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(getTime()));
+        nowTime2.add(Calendar.MINUTE, -5);//5分钟前的时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    public static String getYear(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy");
+        return sp.format(new Date());
+    }
+
+    public static String getMonth(){
+        SimpleDateFormat sp = new SimpleDateFormat("yyyy-MM");
+        return sp.format(new Date());
+    }
+
+    // 获取当前时间
+    public static String getOnlyTime(){
+        SimpleDateFormat sp = new SimpleDateFormat("HH:mm:ss");
+        return sp.format(new Date());
+    }
+    /**
+     * 计算两个日期的时间差
+     * @param time1
+     * @param time2
+     * @return
+     */
+    public static double getTimeDifference(String time1, String time2) {
+        SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long t1 = 0L;
+        long t2 = 0L;
+        try {
+            t1 = timeformat.parse(time1).getTime();
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        try {
+            t2 = timeformat.parse(time2).getTime();
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        //因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
+        double hours=(double) ((t2 - t1)/3600000);
+        double minutes=(double) (((t2 - t1)/1000-hours*3600)/60/60);
+        return hours+minutes;
+    }
+
+    public static double getOnlyTimeDifference(String time1, String time2) {
+        SimpleDateFormat timeformat = new SimpleDateFormat("HH:mm:ss");
+        long t1 = 0L;
+        long t2 = 0L;
+        try {
+            t1 = timeformat.parse(time1).getTime();
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        try {
+            t2 = timeformat.parse(time2).getTime();
+        } catch (ParseException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        //因为t1-t2得到的是毫秒级,所以要初3600000得出小时.算天数或秒同理
+        double hours=(double) ((t2 - t1)/3600000);
+        double minutes=(double) (((t2 - t1)/1000-hours*3600)/60/60);
+        return hours+minutes;
+    }
+
+    public static double getDiff(String str1, String str2){
+        return str2.compareTo(str1);
+    }
+
+    /**
+     * String 转 Date
+     * @param time 时间
+     * @param formatStr 自定义时间格式
+     * @return
+     * @throws ParseException
+     */
+    public static Date ShortStringToDate(String time, String formatStr) throws ParseException {
+
+        Date date = new Date();
+        // 注意format的格式要与日期String的格式相匹配
+        DateFormat dateFormat = new SimpleDateFormat(formatStr);
+        try {
+            date = dateFormat.parse(time);
+            System.out.println(date.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return date;
+    }
+
+    /**
+     * 获取指定月份有多少天
+     *
+     * @param month
+     * @return
+     */
+    public static int getMonthDays(String date, int month) {
+        int year = Integer.valueOf(date.substring(0, 4));
+        int[] arr = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+        int day = arr[month - 1];//天数对应=数组-1
+        if (month == 2 && year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
+            day = 29;
+        }
+
+        return day;
+
+    }
+
+    /**
+     * Date转为String
+     * @param time 时间
+     * @param FormatStr 自定义时间格式
+     * @return
+     */
+    public static String DateToString(Date time, String FormatStr) {
+        String dateStr = "";
+        DateFormat dateFormat = new SimpleDateFormat(FormatStr);
+        try {
+            dateStr = dateFormat.format(time);
+            System.out.println(dateStr);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return dateStr;
+    }
+
+    /**
+     * 比较时间1是否小于时间2
+     * 如果时间1小于时间2,接口返回true
+     * 如果时间1大于时间2,接口返回false
+     * @param dateOne 时间1
+     * @param dateTwo 时间2
+     * @return
+     * @throws ParseException
+     */
+    public static boolean CompareDate(String dateOne, String dateTwo) throws ParseException {
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date sd1=df.parse(dateOne);
+        Date sd2=df.parse(dateTwo);
+        return sd1.before(sd2);
+    }
+
+    /**
+     * 比较时间1是否小于时间2
+     * 如果时间1小于时间2,接口返回true
+     * 如果时间1大于时间2,接口返回false
+     *
+     * @param dateOne 时间1
+     * @param dateTwo 时间2
+     * @param Forma   时间格式
+     * @return
+     * @throws ParseException
+     */
+    public static boolean CompareDate(String dateOne, String dateTwo, String Forma) throws ParseException {
+        SimpleDateFormat df = new SimpleDateFormat(Forma);
+        Date sd1 = df.parse(dateOne);
+        Date sd2 = df.parse(dateTwo);
+        return sd1.before(sd2);
+    }
+
+    /**
+     * 时间加减天数
+     *
+     * @param time   时间
+     * @param amount 天数 负的为减多少天 正的为加多少天
+     * @return
+     * @throws ParseException
+     */
+    public static String TimeDesD(String time, int amount) throws ParseException {
+        Calendar nowTime2 = Calendar.getInstance();
+        nowTime2.setTime(StringToDate(time, "yyyy-MM-dd"));
+        nowTime2.add(Calendar.DATE, amount);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        return simpleDateFormat.format(nowTime2.getTime());
+    }
+
+    /**
+     * 相差的天数
+     */
+    public static int daysBetween(String smdate, String bdate) throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(sdf.parse(smdate));
+        long time1 = cal.getTimeInMillis();
+        cal.setTime(sdf.parse(bdate));
+        long time2 = cal.getTimeInMillis();
+        long between_days = (time2 - time1) / (1000 * 3600 * 24);
+
+        return Integer.parseInt(String.valueOf(between_days));
+    }
+
+    /**
+     * 获取一周的开始时间和结束时间
+     * 获取本周星期一作为一周的第一天的起始时间和结束时间
+     *
+     * @return 返回的数据中第一个是开始时间 第二个是结束时间
+     */
+    public static String[] getCurrentWeekTimeFrame() {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTimeZone(TimeZone.getTimeZone("GMT+8"));
+        //start of the week
+        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
+            calendar.add(Calendar.DAY_OF_YEAR,-1);
+        }
+        calendar.add(Calendar.DAY_OF_WEEK, -(calendar.get(Calendar.DAY_OF_WEEK) - 2));
+        //给0的时候查不出数据
+//        calendar.set(Calendar.HOUR_OF_DAY, 0);
+//        calendar.set(Calendar.MINUTE, 0);
+//        calendar.set(Calendar.SECOND, 0);
+//        calendar.set(Calendar.MILLISECOND, 0);
+
+        String startTime = DateToString(calendar.getTime(), "yyyy-MM-dd");
+        //end of the week
+        calendar.add(Calendar.DAY_OF_WEEK, 6);
+        calendar.set(Calendar.HOUR_OF_DAY, 23);
+        calendar.set(Calendar.MINUTE, 59);
+        calendar.set(Calendar.SECOND, 59);
+        calendar.set(Calendar.MILLISECOND, 999);
+        String endTime = DateToString(calendar.getTime());
+        return new String[]{startTime, endTime};
+    }
+
+    /**
+     * 获取指定月份的第一天和最后一天
+     * @param DateStr 指定月份
+     * @return 返回的数据中第一个是开始时间 第二个是结束时间
+     */
+    public static String[] getCurrentMonthTimeFrame(String DateStr) {
+        Calendar c = Calendar.getInstance();//获取Calendar实例
+        c.set(Calendar.YEAR, Integer.parseInt(DateStr.substring(0, 4)));
+        c.set(Calendar.MONTH, Integer.parseInt(DateStr.substring(5, 7).replace("-", "")) - 1);
+
+        c.set(Calendar.DAY_OF_MONTH, 1);
+
+        String startDate = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
+
+        int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
+        c.set(Calendar.DAY_OF_MONTH, lastDay);
+        String endDate = new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
+
+        return new String[]{startDate, endDate};
+    }
+
+    public static List<String> getHighTime(){
+        String year = getYear();
+        return Arrays.asList(year+"-"+"08-30",year+"-"+"08-31",year+"-"+"09-01",year+"-"+"09-02",year+"-"+"09-03",year+"-"+"09-04");
+    }
+
+    public static List<String> getDays(String startTime, String endTime) {
+        // 返回的日期集合
+        List<String> days = new ArrayList<String>();
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        try {
+            Date start = dateFormat.parse(startTime);
+            Date end = dateFormat.parse(endTime);
+            Calendar tempStart = Calendar.getInstance();
+            tempStart.setTime(start);
+
+            Calendar tempEnd = Calendar.getInstance();
+            tempEnd.setTime(end);
+            tempEnd.add(Calendar.DATE, 0);// 日期加1(包含结束)
+            while (tempStart.before(tempEnd)) {
+                days.add(dateFormat.format(tempStart.getTime()));
+                tempStart.add(Calendar.DAY_OF_YEAR, 1);
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return days;
+    }
+
+
+    public static void main(String[] args) throws ParseException {
+        System.out.println(ToSimpleMonth(StringToDate("2023-11","yyyy-MM")));
+    }
+
+}
+

+ 41 - 0
src/main/java/com/template/common/utils/TreeRecordsUtil.java

@@ -0,0 +1,41 @@
+package com.template.common.utils;
+
+import com.template.model.pojo.SmartAuthorGroup;
+import com.template.model.weixin.AuthorListGroup;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class TreeRecordsUtil {
+
+    public static List<AuthorListGroup> queryCommentTreeRecords(Integer pid, List<SmartAuthorGroup> lists) {
+        List<AuthorListGroup> newTrees = new ArrayList<>();
+
+        List<SmartAuthorGroup> datas = lists.stream().filter(e -> e.getParentId().equals(pid)).collect(Collectors.toList());
+
+        for (SmartAuthorGroup data : datas) {
+            AuthorListGroup item = AuthorListGroup.builder()
+                    .id(data.getId())
+                    .parentId(data.getParentId())
+                    .name(data.getName())
+                    .userId(data.getUserId())
+                    .applyId(data.getApplyId())
+                    .updateTime(data.getUpdateTime())
+                    .createUser(data.getCreateUser())
+                    .updateUser(data.getUpdateUser())
+                    .deleted(data.getDeleted())
+                    .build();
+            List<AuthorListGroup> news = queryCommentTreeRecords(item.getId(), lists);
+            if (news == null || news.size() == 0) {
+                newTrees.add(item);
+                continue;
+            } else {
+                item.setAuthorListGroups(news);
+                newTrees.add(item);
+            }
+        }
+
+        return newTrees;
+    }
+}

+ 25 - 0
src/main/java/com/template/common/utils/UUIDUtil.java

@@ -0,0 +1,25 @@
+package com.template.common.utils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Random;
+
+public class UUIDUtil {
+
+    public static long generateID(){
+
+        Random r = new Random();
+        long numbers = 1000000000L + (long)(r.nextDouble() * 999999999L);
+
+        return numbers;
+    }
+
+    public static String getNewDate(){
+        Date nowDate = new Date();// 取当前时间
+        SimpleDateFormat dateFormat = new SimpleDateFormat(
+                "yyyy-MM-dd HH:mm:ss"); // 转换时间格式
+        String date = dateFormat.format(nowDate);
+        return date;
+    }
+
+}

+ 126 - 33
src/main/java/com/template/controller/SmartAuthorGroupController.java

@@ -1,20 +1,26 @@
 package com.template.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.template.annotation.PassToken;
 import com.template.api.SmartAuthorGroupControllerAPI;
-import com.template.common.utils.paramUtils;
-import com.template.model.pojo.SmartAuthorGroup;
+import com.template.common.utils.TimeExchange2;
+import com.template.common.utils.TreeRecordsUtil;
+import com.template.common.utils.UUIDUtil;
 import com.template.model.pojo.SmartAuthorGroup;
+import com.template.model.pojo.SmartAuthority;
 import com.template.model.result.CommonResult;
-import com.template.model.result.PageUtils;
-import com.template.model.vo.ApplyVo;
+import com.template.model.weixin.AuthorAndGroup;
+import com.template.model.weixin.AuthorAndGroup2;
+import com.template.model.weixin.AuthorListGroup;
+import com.template.model.weixin.userAuthor;
 import com.template.services.SmartAuthorGroupService;
+import com.template.services.SmartAuthorityService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import java.text.ParseException;
 import java.util.List;
 
 /**
@@ -30,54 +36,141 @@ public class SmartAuthorGroupController implements SmartAuthorGroupControllerAPI
 
     @Autowired
     private SmartAuthorGroupService smartAuthorGroupService;
+    @Autowired
+    public SmartAuthorityService smartAuthorityService;
 
     /**
      * 新增权限组
-     * @param smartApply 权限组数据
-     * @param bindingResult
+     * @param
+     * @param
      * @return
      */
     @Override
-    public CommonResult insertSmartAuthorGroup(SmartAuthorGroup smartApply, BindingResult bindingResult) {
-        if (bindingResult.hasErrors()) {
-            String st = paramUtils.getParamError(bindingResult);
-            return CommonResult.fail(st);
+    @PassToken
+    public CommonResult insertSmartAuthorGroup(JSONObject jsonObject, Integer samePower) throws ParseException {
+        if (samePower==null){
+            return CommonResult.errorMsg("samePower不能为空");
         }
-
-        int result = smartAuthorGroupService.insertSmartAuthorGroup(smartApply);
-
-        return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
+        // 所有管理员权限一样
+        if (samePower==1){
+            AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
+            SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
+            sa.setId((int) UUIDUtil.generateID());
+            String[] userId = sa.getUserId().split(",");
+            for (int i = 0; i < userId.length; i++) {
+                SmartAuthority smartAuthority = new SmartAuthority();
+                smartAuthority.setUserId(Integer.parseInt(userId[i]));
+                smartAuthority.setGroupId(sa.getId());
+                smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
+                smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
+                smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setCreateUser("admin");
+                smartAuthority.setUpdateUser("admin");
+                smartAuthority.setDeleted(0);
+                smartAuthorityService.insertSmartAuthority(smartAuthority);
+            }
+            sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+            sa.setCreateUser("admin");
+            sa.setUpdateUser("admin");
+            int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
+            return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
+        }
+        // 每个管理员权限不一样
+        if (samePower==2){
+            AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
+            SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
+            sa.setId((int) UUIDUtil.generateID());
+            List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
+            for (int i = 0; i < userAuthors.size(); i++) {
+                SmartAuthority smartAuthority = new SmartAuthority();
+                smartAuthority.setUserId(userAuthors.get(i).getUserId());
+                smartAuthority.setGroupId(sa.getId());
+                smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
+                smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
+                smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setCreateUser("admin");
+                smartAuthority.setUpdateUser("admin");
+                smartAuthority.setDeleted(0);
+                smartAuthorityService.insertSmartAuthority(smartAuthority);
+            }
+            sa.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+            sa.setCreateUser("admin");
+            sa.setUpdateUser("admin");
+            int result = smartAuthorGroupService.insertSmartAuthorGroup(sa);
+            return result > 0 ? CommonResult.ok("添加成功") : CommonResult.fail("添加失败");
+        }
+        return CommonResult.errorMsg("参数格式错误");
     }
 
     /**
      * 更新权限组
-     * @param sa 权限组数据
-     * @param bindingResult
+     * @param
+     * @param
      * @return
      */
     @Override
-    public CommonResult updateSmartAuthorGroupById(SmartAuthorGroup sa, BindingResult bindingResult) {
-        if (bindingResult.hasErrors()) {
-            String st = paramUtils.getParamError(bindingResult);
-            return CommonResult.fail(st);
+    public CommonResult updateSmartAuthorGroupById(JSONObject jsonObject, Integer samePower) throws ParseException {
+        if (samePower==null){
+            return CommonResult.errorMsg("samePower不能为空");
         }
-
-        int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
-        return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
+        // 所有管理员权限一样
+        if (samePower==1){
+            AuthorAndGroup authorAndGroup = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup.class);
+            SmartAuthorGroup sa = authorAndGroup.getSmartAuthorGroup();
+            String[] userId = sa.getUserId().split(",");
+            for (int i = 0; i < userId.length; i++) {
+                SmartAuthority smartAuthority = smartAuthorityService.getSmartById(Integer.parseInt(userId[i]));
+                smartAuthority.setGroupId(sa.getId());
+                smartAuthority.setDepartmentView(authorAndGroup.getDepartment_view());
+                smartAuthority.setDepartmentManage(authorAndGroup.getDepartment_manage());
+                smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setCreateUser("admin");
+                smartAuthority.setUpdateUser("admin");
+                smartAuthority.setDeleted(0);
+                smartAuthorityService.updateSmartAuthority(smartAuthority);
+            }
+            int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
+            return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
+        }
+        // 每个管理员权限不一样
+        if (samePower==2){
+            AuthorAndGroup2 authorAndGroup2 = JSONObject.parseObject(jsonObject.toString(), AuthorAndGroup2.class);
+            SmartAuthorGroup sa = authorAndGroup2.getSmartAuthorGroup();
+            List<userAuthor> userAuthors = authorAndGroup2.getUserAuthors();
+            for (int i = 0; i < userAuthors.size(); i++) {
+                SmartAuthority smartAuthority = smartAuthorityService.getSmartById(userAuthors.get(i).getUserId());
+                smartAuthority.setUserId(userAuthors.get(i).getUserId());
+                smartAuthority.setGroupId(sa.getId());
+                smartAuthority.setDepartmentView(userAuthors.get(i).getDepartment_view());
+                smartAuthority.setDepartmentManage(userAuthors.get(i).getDepartment_manage());
+                smartAuthority.setCreateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setUpdateTime(TimeExchange2.StringToDate(TimeExchange2.getTime(),"yyyy-MM-dd HH:mm:ss"));
+                smartAuthority.setCreateUser("admin");
+                smartAuthority.setUpdateUser("admin");
+                smartAuthority.setDeleted(userAuthors.get(i).getDeleted());
+                smartAuthorityService.updateSmartAuthority(smartAuthority);
+            }
+            int result = smartAuthorGroupService.updateSmartAuthorGroup(sa);
+            return result > 0 ? CommonResult.ok("修改成功") : CommonResult.fail("修改失败");
+        }
+        return CommonResult.errorMsg("参数格式错误");
     }
 
     /**
-     * 权限组分页数据查询
-     * @param currentPage 当前页数
-     * @param pageCount 一页数据条数
-     * @param name 查询名称
+     * 查看权限列表
      * @return
      */
     @Override
-    public CommonResult queryPageSmartAuthorGroups(int currentPage, int pageCount, String name) {
-        PageUtils<SmartAuthorGroup> result = smartAuthorGroupService.queryPageSmartAuthorGroups(currentPage, pageCount, name);
-
-        return CommonResult.ok(result);
+    public CommonResult queryAuthorListGroupList(Integer authorGroupId) {
+        List<SmartAuthorGroup> smartAuthorGroups = smartAuthorGroupService.getAuthorGroupList();
+        List<AuthorListGroup> authorListGroupList = null;
+        if (smartAuthorGroups.size()>0) {
+            authorListGroupList = TreeRecordsUtil.queryCommentTreeRecords(authorGroupId, smartAuthorGroups);
+        }
+        return CommonResult.ok(authorListGroupList);
     }
 
 

+ 258 - 0
src/main/java/com/template/controller/WechatScanLoginController.java

@@ -0,0 +1,258 @@
+package com.template.controller;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.github.pagehelper.util.StringUtil;
+import com.template.annotation.PassToken;
+import com.template.api.WechatScanLoginControllerAPI;
+import com.template.common.constanst.Constanst;
+import com.template.common.result.ResponseStatusEnum;
+import com.template.common.utils.*;
+import com.template.model.pojo.SmartUser;
+import com.template.model.result.CommonResult;
+import com.template.model.result.PageUtils;
+import com.template.model.tongji.*;
+import com.template.model.vo.LoginVO;
+import com.template.model.weixin.AccessToken;
+import com.template.model.weixin.HttpParame;
+import com.template.model.weixin.WechatUserUnionID;
+import com.template.services.SmartUserService;
+import com.template.services.WechatScanLoginService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.net.URLEncoder;
+import java.text.ParseException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Title: WechatScanLoginController
+ * Description: 微信扫码登录controller
+ * 
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+@Controller
+public class WechatScanLoginController implements WechatScanLoginControllerAPI {
+
+	@Autowired
+	private WechatScanLoginService wechatScanLoginService;
+	@Autowired
+	public SmartUserService smartUserService;
+
+	/**
+	 * Title: list
+	 * Description: 重定向到微信扫码登录二维码页面
+	 * 此处显示要微信要扫描的二维码
+	 * 
+	 * @param model
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	@Override
+	public String login(Model model) throws UnsupportedEncodingException {
+		Map<String, String> wechatLoginUrl = wechatScanLoginService.wechatLoginUrl();
+		String url = wechatLoginUrl.get("url");
+		System.out.println(url);
+		return "redirect:" + url;
+	}
+
+	/**
+	 * Title: callback
+	 * Description: 回调地址处理
+	 * 
+	 * @param code
+	 * @param state
+	 * @return
+	 * @return
+	 */
+	@Override
+	public String callback(String code, String state) throws UnsupportedEncodingException {
+		System.out.println(code+"====="+state);
+		if (code != null && state != null) {
+			// 验证state为了用于防止跨站请求伪造攻击
+			String decrypt = AesUtil.decrypt(AesUtil.parseHexStr2Byte(state), AesUtil.PASSWORD_SECRET_KEY, 16);
+			if (!decrypt.equals(Constanst.PWD_MD5 + DateUtils.getYYYYMMdd())) {
+				return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("请勿非法进入", "UTF-8");
+			}
+			AccessToken access = wechatScanLoginService.getAccessToken(code);
+			if (access != null) {
+				String openid = access.getOpenid();
+				SmartUser user = wechatScanLoginService.selectByOpenid(openid);
+				if (user==null) {		/*不存在*/
+					return "redirect:"+HttpParame.FRONT_URI+"/#/login?message=" + URLEncoder.encode("请绑定信息", "UTF-8");
+				} else {
+					String token = JWTUtil.getToken(user);
+					return "redirect:"+HttpParame.FRONT_URI+"/#/wanzai/home?token=" + token;
+				}
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * Title: bindingUserMac
+	 * Description: 跳转到绑定用户系统帐号页面
+	 * @return
+	 */
+	@Override
+	public String bindUserMac(String cardNo) throws UnsupportedEncodingException {
+		if (StringUtils.isBlank(cardNo)){
+			return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/404/404/?message=" + URLEncoder.encode("请输入卡号", "UTF-8");
+		}
+		Map<String, String> wechatLoginUrl = wechatScanLoginService.wechatBindUrl(cardNo);
+		String url = wechatLoginUrl.get("url");
+		System.out.println(url);
+		return "redirect:" + url;
+	}
+
+	@Override
+	public String bindcallback(String code, String state, String cardNo) throws UnsupportedEncodingException {
+		System.out.println(code+"==="+state+"=="+cardNo);
+		if (code != null && state != null) {
+			// 验证state为了用于防止跨站请求伪造攻击
+			String decrypt = AesUtil.decrypt(AesUtil.parseHexStr2Byte(state), AesUtil.PASSWORD_SECRET_KEY, 16);
+			if (!decrypt.equals(Constanst.PWD_MD5 + DateUtils.getYYYYMMdd())) {
+				return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/404/404/?message=" + URLEncoder.encode("请勿非法进入", "UTF-8");
+			}
+			AccessToken access = wechatScanLoginService.getAccessToken(code);
+			if (access != null) {
+				String openid = access.getOpenid();
+				SmartUser user = wechatScanLoginService.selectByOpenid(openid);
+				// 我只是给个例子
+				if (user!=null) {		/*不存在*/
+					return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/404/404/?message=" + URLEncoder.encode("请勿重复绑定", "UTF-8");
+				}
+				SmartUser userc = wechatScanLoginService.selectByCardNo(cardNo);
+				if (userc==null){
+					return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/404/404/?message=" + URLEncoder.encode("未查询到用户信息", "UTF-8");
+				}
+				if (userc.getOpenId()!=null){
+					return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/404/404/?message=" + URLEncoder.encode("请勿重复绑定", "UTF-8");
+				}
+				userc.setOpenId(openid);
+				int m = wechatScanLoginService.updateSmartUser(userc);
+				if (m>0){
+					String token = JWTUtil.getToken(userc);
+					return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/index/?token=" + token;
+				}
+			}
+		}
+		return "redirect:"+HttpParame.FRONT_URI+"pc/#/pages/404/404/?message=" + URLEncoder.encode("绑定失败", "UTF-8");
+	}
+
+	@Override
+	@PassToken
+    public String insertMonthMeter(String month){
+		wechatScanLoginService.insertMonthMeter(month);
+		return "插入完毕";
+	}
+
+	@Override
+	@PassToken
+	public String insertDayMeter(String day){
+		wechatScanLoginService.insertDayMeter(day);
+		return "插入完毕";
+	}
+
+	/**
+	 * Description: 用户类别统计
+	 */
+	@Override
+	@PassToken
+	public CommonResult getUserIdTj(){
+		List<Tj> list = wechatScanLoginService.getUserIdTj();
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 用户总数
+	 */
+	@Override
+	@PassToken
+	public CommonResult getUserIdTjt(){
+		All list = wechatScanLoginService.getUserIdTjt();
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 水表总计
+	 */
+	@Override
+	@PassToken
+	public CommonResult getWaterTj(){
+		DAll list = wechatScanLoginService.getWaterTj();
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 电表总计
+	 */
+	@Override
+	@PassToken
+	public CommonResult getElcTj(){
+		DAll list = wechatScanLoginService.getElcTj();
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 每月水费查询
+	 */
+	@Override
+	@PassToken
+	public CommonResult getMonWater() throws ParseException {
+		List<MonthMeterDetail> list = wechatScanLoginService.getMonWater();
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 每月电费查询
+	 */
+	@Override
+	@PassToken
+	public CommonResult getMonElc() throws ParseException {
+		List<MonthMeterDetail> list = wechatScanLoginService.getMonElc();
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 实时抄表
+	 */
+	@Override
+	@PassToken
+	public CommonResult getMeterMonthPage(@RequestBody MeterMonthData meterMonthData,int currentPage, int pageCount) {
+		PageHelper.startPage(currentPage, pageCount);
+		PageInfo<MeterMonthData> list = wechatScanLoginService.getMeterMonthPage(meterMonthData);
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 实时抄表
+	 */
+	@Override
+	@PassToken
+	public CommonResult getMeterDayPage(@RequestBody MeterMonthData meterMonthData, int currentPage, int pageCount) {
+		PageHelper.startPage(currentPage, pageCount);
+		PageInfo<MeterMonthData> list = wechatScanLoginService.getMeterDayPage(meterMonthData);
+		return CommonResult.ok(list);
+	}
+
+	/**
+	 * Description: 查轨迹
+	 */
+	@Override
+	@PassToken
+	public CommonResult getPosition() {
+		List<List<BigDecimal>> ld = RandomTrackAlgorithm.getPosition();
+		return CommonResult.ok(ld);
+	}
+}

+ 63 - 0
src/main/java/com/template/mapper/WechatScanLoginMapper.java

@@ -0,0 +1,63 @@
+package com.template.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.template.model.pojo.SmartUser;
+import com.template.model.tongji.*;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface WechatScanLoginMapper extends BaseMapper<SmartUser> {
+
+    // 用户类别统计
+    public List<Tj> getUserIdTj();
+
+    // 用户总数
+    public All getUserIdTjt();
+
+    // 水表总计
+    public DAll getWaterTj();
+
+    // 电表总计
+    public DAll getElcTj();
+
+    // 每个月各水表数据统计
+    public List<EnergyTj> getWaterTjByMonAndBuild(String month);
+
+    // 每个月各电表数据统计
+    public List<EnergyTj> getElcTjByMonAndBuild(String month);
+
+    // 每个月每个楼栋查询
+    public EnergyTj getTjByMon(String name,String month,String type);
+
+    public void insertMonthMeter(EnergyTj energyTj);
+
+    public void updateMonthMeter(@Param("energyTj")EnergyTj energyTj);
+
+    // 每天各水表数据统计
+    public List<EnergyTj> getWaterTjByDayAndBuild(String day);
+
+    // 每天各电表数据统计
+    public List<EnergyTj> getElcTjByDayAndBuild(String day);
+
+    public EnergyTj getTjByDay(String name,String day,String type);
+
+    public void insertDayMeter(EnergyTj energyTj);
+
+    public void updateDayMeter(@Param("energyTj")EnergyTj energyTj);
+
+    // 每个月各水表数据
+    public List<Tj> getMonWater(@Param("month")String month);
+
+    // 每个月各电表数据
+    public List<Tj> getMonElc(@Param("month")String month);
+
+    // 区域能耗统计
+    public List<MeterMonthData> getMeterMonthPage(@Param("meterMonthData")MeterMonthData meterMonthData);
+
+    // 实时抄表
+    public List<MeterMonthData> getMeterDayPage(@Param("meterMonthData")MeterMonthData meterMonthData);
+
+}

+ 14 - 0
src/main/java/com/template/model/tongji/All.java

@@ -0,0 +1,14 @@
+package com.template.model.tongji;
+
+public class All {
+
+    public Integer total;
+
+    public Integer getTotal() {
+        return total;
+    }
+
+    public void setTotal(Integer total) {
+        this.total = total;
+    }
+}

+ 16 - 0
src/main/java/com/template/model/tongji/DAll.java

@@ -0,0 +1,16 @@
+package com.template.model.tongji;
+
+import com.template.common.utils.DataBliu;
+
+public class DAll {
+
+    public Double num;
+
+    public Double getNum() {
+        return DataBliu.getTwo(num);
+    }
+
+    public void setNum(Double num) {
+        this.num = num;
+    }
+}

+ 41 - 0
src/main/java/com/template/model/tongji/DayMeterDetail.java

@@ -0,0 +1,41 @@
+package com.template.model.tongji;
+
+public class DayMeterDetail {
+
+    public Integer id;
+    public String meterName;
+    public String meterDate;
+    public String meterPower;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getMeterName() {
+        return meterName;
+    }
+
+    public void setMeterName(String meterName) {
+        this.meterName = meterName;
+    }
+
+    public String getMeterDate() {
+        return meterDate;
+    }
+
+    public void setMeterDate(String meterDate) {
+        this.meterDate = meterDate;
+    }
+
+    public String getMeterPower() {
+        return meterPower;
+    }
+
+    public void setMeterPower(String meterPower) {
+        this.meterPower = meterPower;
+    }
+}

+ 53 - 0
src/main/java/com/template/model/tongji/EnergyTj.java

@@ -0,0 +1,53 @@
+package com.template.model.tongji;
+
+import com.template.common.utils.DataBliu;
+
+public class EnergyTj {
+
+    public Integer id;
+    public String name;
+    public Integer type;
+    public String date;
+    public Double num;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public Double getNum() {
+        return DataBliu.getTwo(num);
+    }
+
+    public void setNum(Double num) {
+        this.num = num;
+    }
+
+}

+ 50 - 0
src/main/java/com/template/model/tongji/MeterMonthData.java

@@ -0,0 +1,50 @@
+package com.template.model.tongji;
+
+public class MeterMonthData {
+
+    public Integer id;
+    public String name;
+    public String date;
+    public Double wNum;
+    public Double eNum;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public Double getwNum() {
+        return wNum;
+    }
+
+    public void setwNum(Double wNum) {
+        this.wNum = wNum;
+    }
+
+    public Double geteNum() {
+        return eNum;
+    }
+
+    public void seteNum(Double eNum) {
+        this.eNum = eNum;
+    }
+}

+ 25 - 0
src/main/java/com/template/model/tongji/MonthMeterDetail.java

@@ -0,0 +1,25 @@
+package com.template.model.tongji;
+
+import java.util.List;
+
+public class MonthMeterDetail {
+
+    public String date;
+    public List<Tj> lt;
+
+    public String getDate() {
+        return date;
+    }
+
+    public void setDate(String date) {
+        this.date = date;
+    }
+
+    public List<Tj> getLt() {
+        return lt;
+    }
+
+    public void setLt(List<Tj> lt) {
+        this.lt = lt;
+    }
+}

+ 24 - 0
src/main/java/com/template/model/tongji/Tj.java

@@ -0,0 +1,24 @@
+package com.template.model.tongji;
+
+public class Tj {
+
+    public String name;
+    public Integer num;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getNum() {
+        return num;
+    }
+
+    public void setNum(Integer num) {
+        this.num = num;
+    }
+
+}

+ 89 - 0
src/main/java/com/template/model/weixin/AccessToken.java

@@ -0,0 +1,89 @@
+package com.template.model.weixin;
+
+/**
+ * <p>Title: AccessToken</p>
+ * <p>Description: 通过code获取access_token</p>
+ * @author fengyong
+ * @date 2018年9月4日
+ */
+public class AccessToken {
+	
+	/**
+	 * 接口调用凭证
+	 */
+	private String access_token;
+	
+	/**
+	 * access_token接口调用凭证超时时间,单位(秒)
+	 */
+	private Integer expires_in;
+	
+	/**
+	 * 用户刷新access_token
+	 */
+	private String refresh_token;
+	
+	/**
+	 * 授权用户唯一标识
+	 */
+	private String openid;
+	
+	/**
+	 * 用户授权的作用域,使用逗号(,)分隔
+	 */
+	private String scope;
+	
+	/**
+	 * 当且仅当该网站应用已获得该用户的userinfo授权时,才会出现该字段。
+	 */
+	private String unionid;
+
+	public String getAccess_token() {
+		return access_token;
+	}
+
+	public void setAccess_token(String access_token) {
+		this.access_token = access_token;
+	}
+
+	public Integer getExpires_in() {
+		return expires_in;
+	}
+
+	public void setExpires_in(Integer expires_in) {
+		this.expires_in = expires_in;
+	}
+
+	public String getRefresh_token() {
+		return refresh_token;
+	}
+
+	public void setRefresh_token(String refresh_token) {
+		this.refresh_token = refresh_token;
+	}
+
+	public String getOpenid() {
+		return openid;
+	}
+
+	public void setOpenid(String openid) {
+		this.openid = openid;
+	}
+
+	public String getScope() {
+		return scope;
+	}
+
+	public void setScope(String scope) {
+		this.scope = scope;
+	}
+
+	public String getUnionid() {
+		return unionid;
+	}
+
+	public void setUnionid(String unionid) {
+		this.unionid = unionid;
+	}
+
+}

+ 36 - 0
src/main/java/com/template/model/weixin/AuthorAndGroup.java

@@ -0,0 +1,36 @@
+package com.template.model.weixin;
+
+import com.template.model.pojo.SmartAuthorGroup;
+
+import java.util.Date;
+
+public class AuthorAndGroup {
+
+    public SmartAuthorGroup smartAuthorGroup;
+    public String department_view;
+    public String department_manage;
+
+    public SmartAuthorGroup getSmartAuthorGroup() {
+        return smartAuthorGroup;
+    }
+
+    public void setSmartAuthorGroup(SmartAuthorGroup smartAuthorGroup) {
+        this.smartAuthorGroup = smartAuthorGroup;
+    }
+
+    public String getDepartment_view() {
+        return department_view;
+    }
+
+    public void setDepartment_view(String department_view) {
+        this.department_view = department_view;
+    }
+
+    public String getDepartment_manage() {
+        return department_manage;
+    }
+
+    public void setDepartment_manage(String department_manage) {
+        this.department_manage = department_manage;
+    }
+}

+ 27 - 0
src/main/java/com/template/model/weixin/AuthorAndGroup2.java

@@ -0,0 +1,27 @@
+package com.template.model.weixin;
+
+import com.template.model.pojo.SmartAuthorGroup;
+
+import java.util.List;
+
+public class AuthorAndGroup2 {
+
+    public SmartAuthorGroup smartAuthorGroup;
+    public List<userAuthor> userAuthors;
+
+    public SmartAuthorGroup getSmartAuthorGroup() {
+        return smartAuthorGroup;
+    }
+
+    public void setSmartAuthorGroup(SmartAuthorGroup smartAuthorGroup) {
+        this.smartAuthorGroup = smartAuthorGroup;
+    }
+
+    public List<userAuthor> getUserAuthors() {
+        return userAuthors;
+    }
+
+    public void setUserAuthors(List<userAuthor> userAuthors) {
+        this.userAuthors = userAuthors;
+    }
+}

+ 101 - 0
src/main/java/com/template/model/weixin/AuthorListGroup.java

@@ -0,0 +1,101 @@
+package com.template.model.weixin;
+
+import lombok.Builder;
+
+import java.util.Date;
+import java.util.List;
+
+@Builder
+public class AuthorListGroup {
+
+    public Integer id;
+    public Integer parentId;
+    public String name;
+    public String userId;
+    public String applyId;
+    public Date updateTime;
+    public String createUser;
+    public String updateUser;
+    public Integer deleted;
+    public List<AuthorListGroup> authorListGroups;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Integer parentId) {
+        this.parentId = parentId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getUserId() {
+        return userId;
+    }
+
+    public void setUserId(String userId) {
+        this.userId = userId;
+    }
+
+    public String getApplyId() {
+        return applyId;
+    }
+
+    public void setApplyId(String applyId) {
+        this.applyId = applyId;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public String getCreateUser() {
+        return createUser;
+    }
+
+    public void setCreateUser(String createUser) {
+        this.createUser = createUser;
+    }
+
+    public String getUpdateUser() {
+        return updateUser;
+    }
+
+    public void setUpdateUser(String updateUser) {
+        this.updateUser = updateUser;
+    }
+
+    public Integer getDeleted() {
+        return deleted;
+    }
+
+    public void setDeleted(Integer deleted) {
+        this.deleted = deleted;
+    }
+
+    public List<AuthorListGroup> getAuthorListGroups() {
+        return authorListGroups;
+    }
+
+    public void setAuthorListGroups(List<AuthorListGroup> authorListGroups) {
+        this.authorListGroups = authorListGroups;
+    }
+}

+ 43 - 0
src/main/java/com/template/model/weixin/HttpParame.java

@@ -0,0 +1,43 @@
+package com.template.model.weixin;
+
+/**
+ * Title: HttpParame Description: 请求参数
+ * @author fengyong
+ * @date 2018年9月3日
+ */
+public class HttpParame {
+
+	// 应用唯一标识
+	public static final String APPID = "appid";
+
+	// 密匙
+	public static final String SECRET = "secret";
+
+	// 微信用户唯一标识
+	public static final String OPENID = "openid";
+
+	// 接口调用凭证
+	public static final String ACCESS_TOKEN = "access_token";
+
+	// 回调地址
+	public static final String REDIRECT_URI = "redirect_uri";
+
+	// 回调地址
+	public static final String BIND_URI = "bind_uri";
+
+	// 前端地址
+	public static final String FRONT_URI = "https://www.campussmartlife.com/smartManage";
+
+	// 网页授权回调地址
+	public static final String AUTHORIZATION_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";
+
+	// 网页授权绑定地址
+	public static final String BIND_URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";
+
+	// 通过code获取access_token
+	public static final String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
+
+	// 此接口用于获取用户个人信息 UnionID机制
+	public static final String GET_UNIONID_URL = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID";
+
+}

+ 65 - 0
src/main/java/com/template/model/weixin/Result.java

@@ -0,0 +1,65 @@
+package com.template.model.weixin;
+
+/**
+ * Title: Result
+ * Description: 返回结果包装对象使用
+ * @author fengyong
+ * @date 2018年9月5日
+ */
+public class Result {
+	/**
+	 * 状态
+	 */
+	private Object status;
+	/**
+	 * 结果
+	 */
+	private Object result;
+	/**
+	 * 消息
+	 */
+	private String message;
+
+	public Result() {
+	}
+
+	public Result(Object status, String message) {
+		this.status = status;
+		this.message = message;
+	}
+
+	public Result(Object status, Object result) {
+		this.status = status;
+		this.result = result;
+	}
+
+	public Result(Object status, Object result, String message) {
+		this.status = status;
+		this.result = result;
+		this.message = message;
+	}
+
+	public Object getStatus() {
+		return status;
+	}
+
+	public void setStatus(Object status) {
+		this.status = status;
+	}
+
+	public Object getResult() {
+		return result;
+	}
+
+	public void setResult(Object result) {
+		this.result = result;
+	}
+
+	public String getMessage() {
+		return message;
+	}
+
+	public void setMessage(String message) {
+		this.message = message;
+	}
+}

+ 135 - 0
src/main/java/com/template/model/weixin/WechatUserUnionID.java

@@ -0,0 +1,135 @@
+package com.template.model.weixin;
+
+import java.util.List;
+
+/**
+ * Title: WechatUserUnionID
+ * Description: 获取用户个人信息(UnionID机制)
+ * @author fengyong
+ * @date 2018年9月5日
+ */
+public class WechatUserUnionID {
+
+	/**
+	 * 普通用户的标识,对当前开发者帐号唯一
+	 */
+	private String openid;
+
+	/**
+	 * 普通用户昵称
+	 */
+	private String nickname;
+
+	/**
+	 * 普通用户性别,1为男性,2为女性
+	 */
+	private Integer sex;
+
+	/**
+	 * 普通用户个人资料填写的省份
+	 */
+	private String province;
+
+	/**
+	 * 普通用户个人资料填写的城市
+	 */
+	private String city;
+
+	/**
+	 * 国家,如中国为CN
+	 */
+	private String country;
+
+	/**
+	 * 用户头像,最后一个数值代表正方形头像大小 (有0、46、64、96、132数值可选,0代表640*640正方形头像) 用户没有头像时该项为空
+	 */
+	private String headimgurl;
+
+	/**
+	 * 用户特权信息,json数组,如微信沃卡用户为(chinaunicom)
+	 */
+	private List<String> privilege;
+
+	/**
+	 * 用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。
+	 */
+	private String unionid;
+
+	public String getOpenid() {
+		return openid;
+	}
+
+	public void setOpenid(String openid) {
+		this.openid = openid;
+	}
+
+	public String getNickname() {
+		return nickname;
+	}
+
+	public void setNickname(String nickname) {
+		this.nickname = nickname;
+	}
+
+	public Integer getSex() {
+		return sex;
+	}
+
+	public void setSex(Integer sex) {
+		this.sex = sex;
+	}
+	
+	public String getSexStr(){
+		if (getSex() != null) return getSex() == 1 ? "男" : "女";
+		return "";
+	}
+
+	public String getProvince() {
+		return province;
+	}
+
+	public void setProvince(String province) {
+		this.province = province;
+	}
+
+	public String getCity() {
+		return city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+
+	public String getCountry() {
+		return country;
+	}
+
+	public void setCountry(String country) {
+		this.country = country;
+	}
+
+	public String getHeadimgurl() {
+		return headimgurl;
+	}
+
+	public void setHeadimgurl(String headimgurl) {
+		this.headimgurl = headimgurl;
+	}
+
+	public List<String> getPrivilege() {
+		return privilege;
+	}
+
+	public void setPrivilege(List<String> privilege) {
+		this.privilege = privilege;
+	}
+
+	public String getUnionid() {
+		return unionid;
+	}
+
+	public void setUnionid(String unionid) {
+		this.unionid = unionid;
+	}
+
+}

+ 42 - 0
src/main/java/com/template/model/weixin/userAuthor.java

@@ -0,0 +1,42 @@
+package com.template.model.weixin;
+
+public class userAuthor {
+
+    public Integer userId;
+    public String department_view;
+    public String department_manage;
+    public Integer deleted;
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public String getDepartment_view() {
+        return department_view;
+    }
+
+    public void setDepartment_view(String department_view) {
+        this.department_view = department_view;
+    }
+
+    public String getDepartment_manage() {
+        return department_manage;
+    }
+
+    public void setDepartment_manage(String department_manage) {
+        this.department_manage = department_manage;
+    }
+
+    public Integer getDeleted() {
+        return deleted;
+    }
+
+    public void setDeleted(Integer deleted) {
+        this.deleted = deleted;
+    }
+
+}

+ 4 - 0
src/main/java/com/template/services/SmartAuthorGroupService.java

@@ -5,6 +5,8 @@ import com.template.model.pojo.SmartAuthorGroup;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.template.model.result.PageUtils;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -23,4 +25,6 @@ public interface SmartAuthorGroupService extends IService<SmartAuthorGroup> {
     int deleteSmartAuthorGroupById(int id);
 
     SmartAuthorGroup getSmartById(int id);
+
+    public List<SmartAuthorGroup> getAuthorGroupList();
 }

+ 63 - 0
src/main/java/com/template/services/WechatScanLoginService.java

@@ -0,0 +1,63 @@
+package com.template.services;
+
+import com.github.pagehelper.PageInfo;
+import com.template.model.pojo.SmartUser;
+import com.template.model.tongji.*;
+import com.template.model.weixin.AccessToken;
+import com.template.model.weixin.WechatUserUnionID;
+import org.apache.ibatis.annotations.Param;
+
+import java.text.ParseException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>Title: WechatScanLoginService</p>
+ * <p>Description: 业务接口 </p>
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+public interface WechatScanLoginService {
+	
+	Map<String,String> wechatLoginUrl();
+
+	Map<String,String> wechatBindUrl(String cardNo);
+	
+	AccessToken getAccessToken(String code);
+	
+	WechatUserUnionID getUserUnionID();
+
+	SmartUser selectByOpenid(String openid);
+
+	SmartUser selectByCardNo(String CardNo);
+
+	int updateSmartUser(SmartUser sa);
+
+	// 用户类别统计
+	public List<Tj> getUserIdTj();
+
+	// 用户总数
+	public All getUserIdTjt();
+
+	// 水表总计
+	public DAll getWaterTj();
+
+	// 电表总计
+	public DAll getElcTj();
+
+	public void insertMonthMeter(String month);
+
+	public void insertDayMeter(String day);
+
+	// 每个月各水表数据
+	public List<MonthMeterDetail> getMonWater() throws ParseException;
+
+	// 每个月各电表数据
+	public List<MonthMeterDetail> getMonElc() throws ParseException;
+
+	// 区域能耗统计
+	public PageInfo<MeterMonthData> getMeterMonthPage(@Param("meterMonthData")MeterMonthData meterMonthData);
+
+	// 实时抄表
+	public PageInfo<MeterMonthData> getMeterDayPage(@Param("meterMonthData")MeterMonthData meterMonthData);
+}

+ 10 - 0
src/main/java/com/template/services/impl/SmartAuthorGroupServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.template.mapper.SmartAuthorGroupMapper;
+import com.template.mapper.SmartAuthorityMapper;
 import com.template.model.pojo.SmartAuthorGroup;
 import com.template.model.pojo.SmartAuthorGroup;
 import com.template.mapper.SmartAuthorGroupMapper;
@@ -61,4 +62,13 @@ public class SmartAuthorGroupServiceImpl extends ServiceImpl<SmartAuthorGroupMap
         SmartAuthorGroup result = smartAuthorGroupMapper.selectById(id);
         return result;
     }
+
+    @Override
+    public List<SmartAuthorGroup> getAuthorGroupList() {
+        QueryWrapper<SmartAuthorGroup> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("deleted", 0);
+        List<SmartAuthorGroup> result = smartAuthorGroupMapper.selectList(queryWrapper);
+        return result;
+    }
+
 }

+ 286 - 0
src/main/java/com/template/services/impl/WechatScanLoginServiceImpl.java

@@ -0,0 +1,286 @@
+package com.template.services.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.github.pagehelper.PageInfo;
+import com.template.common.constanst.Constanst;
+import com.template.common.utils.*;
+import com.template.mapper.SmartUserMapper;
+import com.template.mapper.WechatScanLoginMapper;
+import com.template.model.pojo.SmartUser;
+import com.template.model.tongji.*;
+import com.template.model.weixin.AccessToken;
+import com.template.model.weixin.HttpParame;
+import com.template.model.weixin.WechatUserUnionID;
+import com.template.services.WechatScanLoginService;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>Title: WechatScanLoginServiceImpl</p>
+ * <p>Description: 业务接口实现 </p>
+ * @author fengyong
+ * @date 2018年9月7日
+ */
+@Service
+public class WechatScanLoginServiceImpl implements WechatScanLoginService {
+
+	@Autowired
+	public SmartUserMapper smartUserMapper;
+
+	@Autowired
+	public WechatScanLoginMapper wechatScanLoginMapper;
+
+	/**
+	 * <p>Title: wechatLoginUrl</p>
+	 * <p>Description: 网页授权回调地址处理</p>
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	@Override
+	public Map<String, String> wechatLoginUrl() {
+		String content = Constanst.PWD_MD5+ DateUtils.getYYYYMMdd();
+		byte[] encrypt = AesUtil.encrypt(content, AesUtil.PASSWORD_SECRET_KEY, 16);
+		String parseByte2HexStr = AesUtil.parseByte2HexStr(encrypt);
+		Map<String,String> map = new HashMap<String,String>();
+		String url = HttpParame.AUTHORIZATION_URL;
+		url = url.replaceAll("APPID", PropertiesUtil.getValue(HttpParame.APPID));
+		try {
+			url = url.replaceAll("REDIRECT_URI", URLEncoder.encode(
+					PropertiesUtil.getValue(HttpParame.REDIRECT_URI),"UTF-8"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		//url = url.replaceAll("SCOPE", "snsapi_login");
+		url = url.replaceAll("SCOPE", "snsapi_base");
+		url = url.replace("STATE", parseByte2HexStr);	//加密state进行验证 回调地址当天有效 防止恶意攻击
+		map.put("url", url);
+		return map;
+	}
+
+	@Override
+	public Map<String, String> wechatBindUrl(String cardNo) {
+		String content = Constanst.PWD_MD5+ DateUtils.getYYYYMMdd();
+		byte[] encrypt = AesUtil.encrypt(content, AesUtil.PASSWORD_SECRET_KEY, 16);
+		String parseByte2HexStr = AesUtil.parseByte2HexStr(encrypt);
+		Map<String,String> map = new HashMap<String,String>();
+		String url = HttpParame.BIND_URL;
+		url = url.replaceAll("APPID", PropertiesUtil.getValue(HttpParame.APPID));
+		try {
+			url = url.replaceAll("REDIRECT_URI", URLEncoder.encode(
+					PropertiesUtil.getValue(HttpParame.BIND_URI)+"&cardNo="+cardNo,"UTF-8"));
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+		}
+		//url = url.replaceAll("SCOPE", "snsapi_login");
+		url = url.replaceAll("SCOPE", "snsapi_base");
+		url = url.replace("STATE", parseByte2HexStr);	//加密state进行验证 回调地址当天有效 防止恶意攻击
+		map.put("url", url);
+		return map;
+	}
+	
+	/**
+	 * <p>Title: getAccessToken</p>
+	 * <p>Description: 用户授权后获取用户唯一标识 </p>
+	 * @param code
+	 * @return
+	 */
+	@Override
+	public AccessToken getAccessToken(String code) {
+		String accessTokenUrl = HttpParame.ACCESS_TOKEN_URL;
+		accessTokenUrl = accessTokenUrl.replaceAll("APPID", PropertiesUtil.getValue(HttpParame.APPID));
+		accessTokenUrl = accessTokenUrl.replaceAll("SECRET", PropertiesUtil.getValue(HttpParame.SECRET));
+		accessTokenUrl = accessTokenUrl.replaceAll("CODE", code);
+		String responseContent = HttpClientUtils.getInstance().sendHttpGet(accessTokenUrl);
+		if (responseContent == null || responseContent == "") {
+			return null;
+		}
+		JSONObject parseObject = JSONObject.parseObject(responseContent);
+		AccessToken accessToken = JSONObject.toJavaObject(parseObject, AccessToken.class);
+		return accessToken;
+	}
+
+	/**
+	 * <p>Title: getUserUnionID</p>
+	 * <p>Description: 获取用户统一标识。针对一个微信开放平台帐号下的应用,
+	 * 同一用户的unionid在多个应用中是唯一的。
+	 * 此方法不牵扯到多个应用时候可以不用。
+	 * 
+	 * 此处用到只是为了获取微信扫码用户的省份城市(此信息获取的只是微信用户所填的城市省份,
+	 * 并不是用户的实时位置信息,如果用户未填写是获取不到的。)
+	 * </p>
+	 * @return
+	 */
+	@Override
+	public WechatUserUnionID getUserUnionID() {
+		String unionIDUrl = HttpParame.GET_UNIONID_URL;
+		unionIDUrl = unionIDUrl.replace("ACCESS_TOKEN", PropertiesUtil.getValue(HttpParame.ACCESS_TOKEN));
+		unionIDUrl = unionIDUrl.replace("OPENID", PropertiesUtil.getValue(HttpParame.OPENID));
+		String responseContent = HttpClientUtils.getInstance().sendHttpGet(unionIDUrl);
+		if (responseContent == null || responseContent == "") {
+			return null;
+		}
+		JSONObject parseObject = JSONObject.parseObject(responseContent);
+		WechatUserUnionID userUnionID = JSONObject.toJavaObject(parseObject, WechatUserUnionID.class);
+		return userUnionID;
+	}
+
+	@Override
+	public SmartUser selectByOpenid(String openid){
+		QueryWrapper<SmartUser> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq( "open_id", openid);
+		List<SmartUser> users = smartUserMapper.selectList(queryWrapper);
+		if (users==null || users.size()<=0){
+			return null;
+		}
+		return users.get(0);
+	}
+
+	@Override
+	public SmartUser selectByCardNo(String CardNo){
+		QueryWrapper<SmartUser> queryWrapper = new QueryWrapper<>();
+		queryWrapper.eq( "card_no", CardNo);
+		List<SmartUser> users = smartUserMapper.selectList(queryWrapper);
+		if (users==null || users.size()<=0){
+			return null;
+		}
+		return users.get(0);
+	}
+
+	@Override
+	public int updateSmartUser(SmartUser sa) {
+		int result = smartUserMapper.updateById(sa);
+		return result;
+	}
+
+	// 用户类别统计
+	@Override
+	public List<Tj> getUserIdTj(){
+		return wechatScanLoginMapper.getUserIdTj();
+	}
+
+	// 用户总数
+	@Override
+	public All getUserIdTjt(){
+		return wechatScanLoginMapper.getUserIdTjt();
+	}
+
+	// 水表总计
+	@Override
+	public DAll getWaterTj(){
+		return wechatScanLoginMapper.getWaterTj();
+	}
+
+	// 电表总计
+	@Override
+	public DAll getElcTj(){
+		return wechatScanLoginMapper.getElcTj();
+	}
+
+	@Override
+	public void insertMonthMeter(String month){
+		List<EnergyTj> waterl = wechatScanLoginMapper.getWaterTjByMonAndBuild(month);
+		List<EnergyTj> elcl = wechatScanLoginMapper.getElcTjByMonAndBuild(month);
+		for (int i = 0; i < waterl.size(); i++) {
+			EnergyTj e = wechatScanLoginMapper.getTjByMon(waterl.get(i).getName(),month,"0");
+			if (e==null){
+				waterl.get(i).setType(0);waterl.get(i).setDate(month);
+				wechatScanLoginMapper.insertMonthMeter(waterl.get(i));
+			} else {
+				waterl.get(i).setId(e.getId());
+				wechatScanLoginMapper.updateMonthMeter(waterl.get(i));
+			}
+		}
+		for (int j = 0; j < elcl.size(); j++) {
+			EnergyTj w = wechatScanLoginMapper.getTjByMon(elcl.get(j).getName(),month,"1");
+			if (w==null){
+				elcl.get(j).setType(1);elcl.get(j).setDate(month);
+				wechatScanLoginMapper.insertMonthMeter(elcl.get(j));
+			} else {
+				elcl.get(j).setId(w.getId());
+				wechatScanLoginMapper.updateMonthMeter(elcl.get(j));
+			}
+		}
+	}
+
+	@Override
+	public void insertDayMeter(String day){
+		List<EnergyTj> waterl = wechatScanLoginMapper.getWaterTjByDayAndBuild(day);
+		List<EnergyTj> elcl = wechatScanLoginMapper.getElcTjByDayAndBuild(day);
+		for (int i = 0; i < waterl.size(); i++) {
+			EnergyTj w = wechatScanLoginMapper.getTjByDay(waterl.get(i).getName(),day,"0");
+			if (w==null){
+				waterl.get(i).setType(0);waterl.get(i).setDate(day);
+				wechatScanLoginMapper.insertDayMeter(waterl.get(i));
+			} else {
+				waterl.get(i).setId(w.getId());
+				wechatScanLoginMapper.updateDayMeter(waterl.get(i));
+			}
+		}
+		for (int j = 0; j < elcl.size(); j++) {
+			EnergyTj e = wechatScanLoginMapper.getTjByDay(elcl.get(j).getName(),day,"1");
+			if (e==null){
+				elcl.get(j).setType(1);elcl.get(j).setDate(day);
+				wechatScanLoginMapper.insertDayMeter(elcl.get(j));
+			} else {
+				elcl.get(j).setId(e.getId());
+				wechatScanLoginMapper.updateDayMeter(elcl.get(j));
+			}
+		}
+	}
+
+	// 每个月各水表数据
+	@Override
+	public List<MonthMeterDetail> getMonWater() throws ParseException {
+		List<String> dates = TimeExchange2.getLastSevenMonth();
+		List<MonthMeterDetail> lm = new ArrayList<>();
+		for (int i = 0; i < dates.size(); i++) {
+			MonthMeterDetail mm = new MonthMeterDetail();
+			List<Tj> list = wechatScanLoginMapper.getMonWater(dates.get(i));
+			mm.setDate(TimeExchange2.ToSimpleMonth(TimeExchange2.StringToDate(dates.get(i),"yyyy-MM"))+"月");
+			mm.setLt(list);
+			lm.add(mm);
+		}
+		return lm;
+	}
+
+	// 每个月各电表数据
+	@Override
+	public List<MonthMeterDetail> getMonElc() throws ParseException {
+		List<String> dates = TimeExchange2.getLastSevenMonth();
+		List<MonthMeterDetail> lm = new ArrayList<>();
+		for (int i = 0; i < dates.size(); i++) {
+			MonthMeterDetail mm = new MonthMeterDetail();
+			List<Tj> list = wechatScanLoginMapper.getMonElc(dates.get(i));
+			mm.setDate(TimeExchange2.ToSimpleMonth(TimeExchange2.StringToDate(dates.get(i),"yyyy-MM"))+"月");
+			mm.setLt(list);
+			lm.add(mm);
+		}
+		return lm;
+	}
+
+	// 区域能耗统计
+	@Override
+	public PageInfo<MeterMonthData> getMeterMonthPage(@Param("meterMonthData")MeterMonthData meterMonthData){
+		List<MeterMonthData> list = wechatScanLoginMapper.getMeterMonthPage(meterMonthData);
+		PageInfo<MeterMonthData> meterPageInfo = new PageInfo<>(list);
+		return meterPageInfo;
+	}
+
+	// 实时抄表
+	@Override
+	public PageInfo<MeterMonthData> getMeterDayPage(@Param("meterMonthData")MeterMonthData meterMonthData){
+		List<MeterMonthData> list = wechatScanLoginMapper.getMeterDayPage(meterMonthData);
+		PageInfo<MeterMonthData> meterPageInfo = new PageInfo<>(list);
+		return meterPageInfo;
+	}
+}

+ 206 - 0
src/main/resources/mapper/template/WechatScanLoginMapper.xml

@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.template.mapper.WechatScanLoginMapper">
+
+    <resultMap id="Tj" type="com.template.model.tongji.Tj">
+        <result property="name" column="name"/>
+        <result property="num" column="num"/>
+    </resultMap>
+
+    <resultMap id="Tjt" type="com.template.model.tongji.All">
+        <result property="total" column="total"/>
+    </resultMap>
+
+    <resultMap id="Elct" type="com.template.model.tongji.DAll">
+        <result property="num" column="num"/>
+    </resultMap>
+
+    <resultMap id="Energy" type="com.template.model.tongji.EnergyTj">
+        <result property="name" column="name"/>
+        <result property="num" column="num"/>
+    </resultMap>
+
+    <resultMap id="MonthT" type="com.template.model.tongji.EnergyTj">
+        <result property="id" column="id"/>
+        <result property="name" column="name"/>
+        <result property="type" column="type"/>
+        <result property="date" column="date"/>
+        <result property="num" column="num"/>
+    </resultMap>
+
+    <resultMap id="DayT" type="com.template.model.tongji.EnergyTj">
+        <result property="id" column="id"/>
+        <result property="name" column="name"/>
+        <result property="type" column="type"/>
+        <result property="date" column="date"/>
+        <result property="num" column="num"/>
+    </resultMap>
+
+    <resultMap id="meterMonthData" type="com.template.model.tongji.MeterMonthData">
+        <result property="id" column="id"/>
+        <result property="name" column="name"/>
+        <result property="date" column="date"/>
+        <result property="wNum" column="w_num"/>
+        <result property="eNum" column="e_num"/>
+    </resultMap>
+
+    <!--用户类别统计-->
+    <select id="getUserIdTj" parameterType="com.template.model.tongji.Tj" resultMap="Tj">
+        select a.name,IFNULL(b.num,0) as num from `smart_identity` a
+        left join (
+            select identity_id,COUNT(*) as num from `smart_user`
+            where is_cancel=0 and deleted=0 group by identity_id ) b
+        on a.id=b.identity_id
+    </select>
+
+    <!--用户总数-->
+    <select id="getUserIdTjt" parameterType="com.template.model.tongji.Tj" resultMap="Tjt">
+        select count(*) as total from `smart_user` where is_cancel=0 and deleted=0
+    </select>
+
+    <!--水表总计-->
+    <select id="getWaterTj" parameterType="com.template.model.tongji.Tj" resultMap="Elct">
+        select ifnull(sum(meter_power),0) as num from `smart_meter_detail` where meter_type=0 and deleted=0
+    </select>
+
+    <!--电表总计-->
+    <select id="getElcTj" parameterType="com.template.model.tongji.Tj" resultMap="Elct">
+        select ifnull(sum(meter_power),0) as num from `smart_meter_detail` where meter_type=1 and deleted=0
+    </select>
+
+    <!--每个月各水表数据统计-->
+    <select id="getWaterTjByMonAndBuild" parameterType="String" resultMap="Energy">
+        select a.name,SUM(IFNULL(b.num,0)) as num from `smart_build` a left join (
+            select a.`build_id`,IFNULL(b.num,0) as num from `smart_build_meter` a left join (
+            select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
+            where deleted=0 and meter_type=0 and update_time like concat(#{month}, '%')
+            group by meter_id ) b on a.`meter_id`=b.`meter_id`) b on a.id=b.build_id
+        group by a.`name`
+    </select>
+
+    <!--每个月各电表数据统计-->
+    <select id="getElcTjByMonAndBuild" parameterType="String" resultMap="Energy">
+        select a.name,SUM(IFNULL(b.num,0)) as num from `smart_build` a left join (
+            select a.`build_id`,IFNULL(b.num,0) as num from `smart_build_meter` a left join (
+                select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
+                where deleted=0 and meter_type=1 and update_time like concat(#{month}, '%')
+                group by meter_id ) b on a.`meter_id`=b.`meter_id`) b on a.id=b.build_id
+        group by a.`name`
+    </select>
+
+    <!--每个月每个楼栋查询-->
+    <select id="getTjByMon" parameterType="String" resultMap="MonthT">
+        select * from `month_meter_detail` where `name`=#{name} and `date`=#{month} and `type`=#{type}
+    </select>
+
+    <insert id="insertMonthMeter" parameterType="com.template.model.tongji.EnergyTj" useGeneratedKeys="true">
+        INSERT INTO `month_meter_detail`
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="name != null">`name`,</if>
+            <if test="type != null">`type`,</if>
+            <if test="date != null">`date`,</if>
+            <if test="num != null">`num`,</if>
+        </trim>
+        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            <if test="name != null">#{name},</if>
+            <if test="type != null">#{type},</if>
+            <if test="date != null">#{date},</if>
+            <if test="num != null">#{num},</if>
+        </trim>
+    </insert>
+
+    <update id="updateMonthMeter">
+        UPDATE `month_meter_detail`
+        <trim prefix="SET" suffixOverrides=",">
+            num=#{energyTj.num}
+        </trim>
+        <where>
+            and id=#{energyTj.id}
+        </where>
+    </update>
+
+    <!--每天各水表数据统计-->
+    <select id="getWaterTjByDayAndBuild" parameterType="String" resultMap="Energy">
+        select a.name,SUM(IFNULL(b.num,0)) as num from `smart_build` a left join (
+            select a.`build_id`,IFNULL(b.num,0) as num from `smart_build_meter` a left join (
+                select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
+                where deleted=0 and meter_type=0 and update_time like concat(#{day}, '%')
+                group by meter_id ) b on a.`meter_id`=b.`meter_id`) b on a.id=b.build_id
+        group by a.`name`
+    </select>
+
+    <!--每天各电表数据统计-->
+    <select id="getElcTjByDayAndBuild" parameterType="String" resultMap="Energy">
+        select a.name,SUM(IFNULL(b.num,0)) as num from `smart_build` a left join (
+            select a.`build_id`,IFNULL(b.num,0) as num from `smart_build_meter` a left join (
+                select meter_id,IFNULL(SUM(meter_power),0) as num from `smart_meter_detail`
+                where deleted=0 and meter_type=1 and update_time like concat(#{day}, '%')
+                group by meter_id ) b on a.`meter_id`=b.`meter_id`) b on a.id=b.build_id
+        group by a.`name`
+    </select>
+
+    <select id="getTjByDay" parameterType="String" resultMap="DayT">
+        select * from `day_meter_detail` where `name`=#{name} and `date`=#{day} and `type`=#{type}
+    </select>
+
+    <insert id="insertDayMeter" parameterType="com.template.model.tongji.EnergyTj" useGeneratedKeys="true">
+        INSERT INTO `day_meter_detail`
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="name != null">`name`,</if>
+            <if test="type != null">`type`,</if>
+            <if test="date != null">`date`,</if>
+            <if test="num != null">`num`,</if>
+        </trim>
+        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+            <if test="name != null">#{name},</if>
+            <if test="type != null">#{type},</if>
+            <if test="date != null">#{date},</if>
+            <if test="num != null">#{num},</if>
+        </trim>
+    </insert>
+
+    <update id="updateDayMeter">
+        UPDATE `day_meter_detail`
+        <trim prefix="SET" suffixOverrides=",">
+            num=#{energyTj.num}
+        </trim>
+        <where>
+            and id=#{energyTj.id}
+        </where>
+    </update>
+
+    <!--每个月水费数据-->
+    <select id="getMonWater" parameterType="String" resultMap="Tj">
+        select * from `month_meter_detail` where type=0 and `date`=#{month}
+    </select>
+
+    <!--每个月电费数据-->
+    <select id="getMonElc" parameterType="String" resultMap="Tj">
+        select * from `month_meter_detail` where type=1 and `date`=#{month}
+    </select>
+
+    <!--区域能耗统计-->
+    <select id="getMeterMonthPage" resultMap="meterMonthData">
+        select * from (select a.id,a.`name`,a.`date`,a.`num` w_num,b.num as e_num
+           from `month_meter_detail` a,`month_meter_detail` b
+           where a.`type`=0 and b.`type`=1 and a.name=b.`name`
+             and a.`date`=b.`date` ) a
+        <where>
+            <if test="meterMonthData.date != null and meterMonthData.date != ''"> AND a.date like concat(#{meterMonthData.date}, '%')</if>
+        </where>
+        order by a.date desc
+    </select>
+
+    <!--实时抄表-->
+    <select id="getMeterDayPage" resultMap="meterMonthData">
+        select * from (select a.id,a.`name`,a.`date`,a.`num` w_num,b.num as e_num
+        from `day_meter_detail` a,`day_meter_detail` b
+        where a.`type`=0 and b.`type`=1 and a.name=b.`name`
+        and a.`date`=b.`date` ) a
+        <where>
+            <if test="meterMonthData.date != null and meterMonthData.date != ''"> AND a.date like concat(#{meterMonthData.date}, '%')</if>
+        </where>
+        order by a.date desc
+    </select>
+
+</mapper>