Commit c58bbd6c authored by 李良停's avatar 李良停

llt

parents
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.chineseall.djgdata</groupId>
<artifactId>djgdata</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.16.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-version>4.3.19.RELEASE</spring-version>
<spring.version>4.3.19.RELEASE</spring.version>
<alpha-framework-version>2.0.6.0014</alpha-framework-version>
<spring-boot.version>1.5.16.RELEASE</spring-boot.version>
<mongodb.version>3.10.2</mongodb.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-api</artifactId>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-springboot-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-springboot-starter</artifactId>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-dao-core</artifactId>
<version>${alpha-framework-version}</version>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-dao-mongo</artifactId>
<version>${alpha-framework-version}</version>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-dao-mysql</artifactId>
<version>${alpha-framework-version}</version>
</dependency>
<!--因配置外部TOMCAT 而配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-api</artifactId>
<version>${alpha-framework-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-springboot-bootstrap</artifactId>
<version>${alpha-framework-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-core</artifactId>
<version>${alpha-framework-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-dao-mongo</artifactId>
<version>${alpha-framework-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.sh.chineseall</groupId>
<artifactId>alpha-framework-springboot-starter</artifactId>
<version>${alpha-framework-version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
<repository>
<id>public</id>
<url>http://180.167.91.206:5716/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
package com.chineseall.djgdata;
import cn.sh.chineseall.framework.starter.annotation.AlphaFrameworkApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@AlphaFrameworkApplication
@ComponentScan(basePackages = {"com.chineseall.djgdata"})
@EnableScheduling
public class EdenAuthcenterAgentApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(EdenAuthcenterAgentApplication.class);
}
public static void main(String[] args) {
cn.sh.chineseall.framework.springboot.bootstrap.application.AlphaFrameworkSpringApplication.run(EdenAuthcenterAgentApplication.class, args);
}
}
package com.chineseall.djgdata.common.enums;
public enum BookType {
PAPER("PAPER", "纸质"),
DIGITAL("DIGITAL","数字");
private String code;
private String desc;
private BookType(String code, String desc) {
this.code = code;
this.desc = desc;
}
public String getCode() {
return this.code;
}
public String getDesc() {
return this.desc;
}
public static BookType findResultEnum(String code) {
for (BookType resultEnum : values()) {
if (resultEnum.getCode().equals(code)) {
return resultEnum;
}
}
return null;
}
}
package com.chineseall.djgdata.common.enums;
/**
* 结果枚举,作为消息信息
*/
public enum ResultEnum {
/**
* 所有失败的操作均指定为999,未知错误
*/
Error(999, "失败"),
/**
* 令牌不合法
*/
TokenUnValidate(998, "令牌不合法"),
/**
* 签名不合法
*/
SignUnValidate(997, "签名不合法"),
/**
* 签名丢失
*/
SignHeaderMiss(996, "必须传递签名、过期时间和appId"),
/**
* 签名过期
*/
SignTimeOver(995, "签名过期"),
/**
* 用户名或者密码不正确
*/
ErrorUserNameOrPassword(994, "用户名或者密码不正确"),
UserNameInvalid(9941, "用户名无效"),
PasswordIncorrect(9942, "密码不正确"),
AccountDisabled(9943, "账户已冻结"),
/**
* APPID缺失
*/
MissAppId(993, "APP_ID缺失或者不正确"),
UnSupportUserType(992,"不支持的用户类型"),
/**
* 签名时间错误
*/
DeviceLocalTimeError(991,"设备传递的CHINESEALL_SIGN_EXP错误"),
/**
* 成功
*/
Success(1, "成功"),
/**
* 数据库操作失败
*/
DBError(1015, "数据库操作错误"),
/**
* 参数不全
*/
ParamsNull(1002, "参数不全"),
/**
* 不支持的HTTP方法
*/
MethodNotSupport(1001, "不支持的HTTP方法"),
NoHandlerFoundException(1003, "请求的方法不存在"),
SaveAnnotationError(2001, "保存云笔记失败"),
SaveAttachError(2002, "保存附件信息失败"),
SaveAnnotationTagError(2003, "创建云笔记与标签关系失败"),
AnnotationNotExist(2004, "云笔记不存在"),
ShareAnnotationError(2005, "分享笔记失败"),
SaveTagError(2006, "保存标签失败"),
UpdateTagError(2007, "更新标签失败"),
DeleteTagError(2008, "删除标签失败"),
SaveFolderError(2009, "创建文件夹失败"),
FolderNotExist(2010, "文件夹不存在"),
FolderOverdue(2011, "文件夹过期"),
AnnotationIdNull(2012, "笔记id为空"),
AnnotationDeleteError(2013, "删除云笔记失败"),
ShareIdNull(2014, "分享笔记id为空"),
ShareAnnotationNotExist(2015, "分享笔记不存在"),
TagTooMuch(2016, "标签创建过多"),
RegionError(2017, "区域代码错误"),
OrgIdError(2018, "机构代码错误"),
ForbiddenRequest(4000, "不在网关放行许可内"),
ConfigAuthCodeNull(3100, "获取配置信息授权码为空"),
GetConfigError(3001, "获取配置信息失败"),
/**
* 请求数据错误
*/
DataInvalid(1500,"请求数据无效"),
ReadingDataInvalid(1501,"阅读数据无效"),
JobAlreadyRun(1501,"该时间段任务已经执行过"),
JobRunning(1502,"任务正在执行");
private Integer code;
private String message;
private ResultEnum(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer getCode() {
return this.code;
}
public String getMessage() {
return this.message;
}
public static ResultEnum findResultEnum(Integer code) {
for (ResultEnum resultEnum : values()) {
if (resultEnum.getCode().equals(code)) {
return resultEnum;
}
}
return null;
}
}
package com.chineseall.djgdata.common.utils;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
public static Date getBeginTime(Date date){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
}
package com.chineseall.djgdata.common.utils;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import javax.crypto.*;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
public class EncodeUtil {
private static final String charset = "utf-8";
private static final String KEY_ALGORITHM = "AES";
private static final String CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
private static final String key = "ChineseAllShanghai!@#$%^&*()";
public static String encodePassword(String originPassword) {
return EncodeUtil.base64Encode(
EncodeUtil.md5(originPassword + key), "UTF-8").trim();
}
/**
* 根据指定的字符串生成密钥
* @param len 密钥长度;支持128、192、256三种长度,本项目采用128位。
*
* @return String 密钥
*/
public static String getKey(String key, int len) throws Exception {
if (len != 128 && len != 192 && len != 256)
return null;
key = EncodeUtil.md5(key);
key = key.substring(0, len / 8);
byte[] kb = key.getBytes(charset);
key = EncodeUtil.encodeBase64(kb);
return key;
}
private static Key toKey(byte[] key)
{
return new SecretKeySpec(key, KEY_ALGORITHM);
}
public static String encrypt(String data, String key) throws Exception
{
//Key k = toKey(Base64.decode(key));
Key k = toKey(EncodeUtil.decodeBase64(key).getBytes(charset));
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, k);
String content = parseByte2HexStr(Base64.encodeBase64((cipher.doFinal(data.getBytes(charset)))));
return content;
}
public static String decrypt(String data, String key) throws Exception
{
Key k = toKey(EncodeUtil.decodeBase64(key).getBytes(charset));
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, k);
String content = new String(cipher.doFinal(Base64.decodeBase64(parseHexStr2Byte(data))), charset);
return content;
}
/**将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;
}
/**将二进制转换成16进制
* @param buf
* @return
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
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();
}
/**
* 传入字符串,返回一个加密串
*
* @param s
* @return
*/
public static String encode(String s , String key) {
try {
byte[] encryptedData = encrypt(s , HEXStringToByte(key));
s = byteToHEXString(encryptedData);
} catch (Exception e) {
e.printStackTrace();
}
return s;
}
/**
* 传入加密串,返回解密串
*
* @param s
* @return
*/
public static String decode(String s , String key) {
try {
return decrypt(HEXStringToByte(s) , HEXStringToByte(key));
} catch (Exception e) {
}
return s;
}
/**
* 传入字符串,返回一个加密串
*
* @param s
* @return
*/
public static String encodeBase64(String s) {
byte[] binaryData = null;
try {
binaryData = s.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
return s;
}
// byte[] newbt = Base64.encodeBase64(binaryData);
return encodeBase64(binaryData);// new String(newbt);
}
public static String encodeBase64(byte[] binaryData) {
byte[] newbt = Base64.encodeBase64(binaryData);
return new String(newbt);
}
public static byte[] enBase64(byte[] binaryData) {
return Base64.encodeBase64(binaryData);
}
public static byte[] deBase64(byte[] bytes) throws IOException {
return Base64.decodeBase64(bytes);
}
public static String stringEncode(String str) {
try {
return java.net.URLEncoder.encode(str, "utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
/**
* 传入加密串,返回解密串
*
* @param s
* @return
*/
public static String decodeBase64(String s) {
try {
return decodeBase64(s.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
return s;
}
}
public static String decodeBase64(byte[] bytes) {
byte[] oldbt = null;
String t = null;
try {
oldbt = Base64.decodeBase64(bytes);
t = new String(oldbt, "utf-8");
} catch (UnsupportedEncodingException e) {
}
return t;
}
public static String byteToHEXString(byte[] bArray) {
StringBuilder sb = new StringBuilder(100);
for (int i = 0; i < bArray.length; i++) {
String hex = Integer.toHexString(bArray[i] & 0xff);
if (hex.length() == 1) {
sb.append("0").append(hex);
} else {
sb.append(hex);
}
}
return sb.toString().toUpperCase();
}
public static byte[] HEXStringToByte(String strString) {
byte[] ret = new byte[strString.length() / 2];
for (int i = 0; i < ret.length; i++) {
ret[i] = Integer
.decode("#" + strString.substring(2 * i, 2 * i + 2))
.byteValue();
}
return ret;
}
/**
* 加密方法
*
* @param rawKeyData
* @param str
* @return
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws NoSuchPaddingException
* @throws InvalidKeySpecException
* @throws UnsupportedEncodingException
*/
public static byte[] encrypt(String str , byte [] rawKeyData) throws InvalidKeyException,
NoSuchAlgorithmException, IllegalBlockSizeException,
BadPaddingException, NoSuchPaddingException,
InvalidKeySpecException, UnsupportedEncodingException {
// DES算法要求有一个可信任的随机数源
// SecureRandom sr = new SecureRandom();
// 从原始密匙数据创建一个DESKeySpec对象
DESKeySpec dks = new DESKeySpec(rawKeyData);
// 创建一个密匙工厂,然后用它把DESKeySpec转换成一个SecretKey对象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, key);
// 现在,获取数据并加密
byte data[] = str.getBytes("utf-8");
// 正式执行加密操作
byte[] encryptedData = cipher.doFinal(data);
return encryptedData;
}
/**
* 解密方法
*
* @param rawKeyData
* @param encryptedData
* @throws IllegalBlockSizeException
* @throws BadPaddingException
* @throws InvalidKeyException
* @throws NoSuchAlgorithmException
* @throws NoSuchPaddingException
* @throws InvalidKeySpecException
* @throws UnsupportedEncodingException
*/
public static String decrypt(byte[] encryptedData , byte[] rawKeyData)
throws IllegalBlockSizeException, BadPaddingException,
InvalidKeyException, NoSuchAlgorithmException,
NoSuchPaddingException, InvalidKeySpecException,
UnsupportedEncodingException {
// DES算法要求有一个可信任的随机数源
// SecureRandom sr = new SecureRandom();
// 从原始密匙数据创建一个DESKeySpec对象
DESKeySpec dks = new DESKeySpec(rawKeyData);
// 创建一个密匙工厂,然后用它把DESKeySpec对象转换成一个SecretKey对象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey key = keyFactory.generateSecret(dks);
// Cipher对象实际完成解密操作
Cipher cipher = Cipher.getInstance("DES");
// 用密匙初始化Cipher对象
cipher.init(Cipher.DECRYPT_MODE, key);
// 正式执行解密操作
byte decryptedData[] = cipher.doFinal(encryptedData);
return new String(decryptedData, "utf-8");
}
public String getCurrentMillyTime() {
return Long.valueOf(System.currentTimeMillis()).toString();
}
public static String md5(String content) {
return DigestUtils.md5Hex(content);
}
public static String sha(String content) {
return DigestUtils.shaHex(content);
}
public static String base64Encode(String content, String charset) {
byte[] bytes = null;
try {
bytes = Base64.encodeBase64(content.getBytes(charset), true);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new String(bytes);
}
public static String base64Decode(String content, String charset) {
byte[] bytes = null;
try {
bytes = Base64.decodeBase64(content.getBytes(charset));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new String(bytes);
}
}
package com.chineseall.djgdata.common.utils;
import cn.sh.chineseall.framework.core.repackaged.org.apache.commons.lang3.RandomStringUtils;
import cn.sh.chineseall.framework.core.repackaged.org.apache.commons.lang3.StringUtils;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.net.*;
import java.security.MessageDigest;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* <li>描述:公用类</li><br>
*
* @author zhouxiying
* @date 2013-8-28
*/
public class Utils {
/**
* 取出字符串 [1,2,3]中最大值
* */
public static int getMaxValue(String str) {
int max = 0;
// String values=null;
str = str.replace("[", "");
str = str.replace("]", "");
String[] strs = str.split(",");
for (String s : strs) {
if (max < Integer.parseInt(Utils.trim(s))) {
max = Integer.parseInt(Utils.trim(s));
}
}
return max;
}
/**
* 判断字符串数组中是否包含某字符串元素
*
* @return
*/
public static boolean isIn(String substring, String[] source) {
for (int i = 0; i < source.length; i++) {
if (source[i].trim().equals(substring)) {
return true;
}
}
return false;
}
/**
* 对list检查是否包含某元素
*
* @throws Exception
*/
public static boolean isItEquals(List list, String str) throws Exception {
for (int i = 0; i < list.size(); i++) {
if (str.trim().equals(list.get(i).toString())) {
return true;
}
}
return false;
}
/**
* 返回一个整数
*
* @author liuy
* @param str
* @return
* @throws Exception
* @return Integer
* @date 2014-4-10 下午5:39:52
*/
public static Integer isInteger(double str) throws Exception {
int in = 0;
// double in2=1/(double)str;
if (str < 1) {
in = in + 1;
} else if (str >= 1) {
int ioo = (int) str;
in = ioo + 1;
}
return in;
}
/**
* 生成制定位随机数字
*/
public static String randomNumeric(int i) {
return RandomStringUtils.randomNumeric(i);
}
/**
* //保留小数点后3位(四舍五入),且不按科学计数法输出
* */
public static String FormatPrice(double price, int i) {
String revalue = null;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(i);
df.setMinimumFractionDigits(i);
revalue = df.format(price);
revalue = revalue.replaceAll(",", "");
return revalue;
}
/**
* 生成制定位随机字母和数字 生成优惠券号用此(去除了‘0’,‘1’,‘I’,‘O’)
*/
public static String randomAlphanumeric(int i) {
return RandomStringUtils.random(i, new char[] { '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z' });
}
/**
* 判断字符串是否是GB2312编码的
* */
public static boolean isGB2312(String str) {
if (Utils.isObjectNotEmpty(str)) {
return java.nio.charset.Charset.forName("GB2312").newEncoder()
.canEncode(str);
} else {
return false;
}
}
/**
* 获得字符串的实际长度 GBK 编码格式 中文占两个字节
* */
public static int getStrLenth(String str) {
if (str == null || str.length() < 0) {
return 0;
}
int len = 0;
char c;
for (int i = str.length() - 1; i >= 0; i--) {
c = str.charAt(i);
if (c > 255) {
len += 2;
} else {
len++;
}
}
return len;
}
/**
* 冒泡排序
*
* @param list
* 需要排序的集合
* @param type
* 排序类型 0:正序 1:倒序
* */
public static List<String> setValue(List<String> list, int type) {
for (int i = 0; i < list.size(); i++) {// 循环List集合,开始于下标0
for (int j = i + 1; j < list.size(); j++) {// 循环List集合,开始于下标0+1
int a = Integer.parseInt(list.get(i));// 取List集合的第n个值
int b = Integer.parseInt(list.get(j));// 取List集合的第n+1个值
if (type == 0 ? a > b : a < b) {// 如果a比b大,则替换两个值的位置。
list.set(i, b + "");
list.set(j, a + "");
}
}
}
return list;
}
/**
* 返回两数之和
*
* @param a1
* @param a2
* @return a1+a2
*/
public static BigDecimal nwdBcadd(Object a1, Object a2) {
BigDecimal accrual1 = new BigDecimal(a1.toString());
BigDecimal accrual2 = new BigDecimal(a2.toString());
BigDecimal accrual = accrual1.add(accrual2);
return accrual;
}
/**
* 返回两数之差
*
* @param a1
* @param a2
* @return a1-a2
*/
public static BigDecimal nwdBcsub(Object a1, Object a2) {
BigDecimal accrual1 = new BigDecimal(a1.toString());
BigDecimal accrual2 = new BigDecimal(a2.toString());
BigDecimal accrual = accrual1.subtract(accrual2);
return accrual;
}
/**
* 返回两数之积
*
* @param a1
* @param a2
* @return a1*a2
*/
public static BigDecimal nwdMultiply(Object a1, Object a2) {
BigDecimal accrual1 = new BigDecimal(a1.toString());
BigDecimal accrual2 = new BigDecimal(a2.toString());
BigDecimal accrual = accrual1.multiply(accrual2);
return accrual;
}
/**
* 返回两数相除
*
* @param a1
* @param a2
* @return a1/a2
*/
public static BigDecimal nwdDivide(Object a1, Object a2) {
MathContext mc = new MathContext(10, RoundingMode.HALF_DOWN); // 取字符个数为10
BigDecimal accrual1 = new BigDecimal(a1.toString());
BigDecimal accrual2 = new BigDecimal(a2.toString());
BigDecimal accrual = accrual1.divide(accrual2, mc);
return accrual;
}
/**
* 返回小数点后2位
*
* @param object
* @return .00
*/
public static BigDecimal setScale(Object object) {
BigDecimal bd = new BigDecimal(object.toString());
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); // 取小数点后2位 /ROUND_HALF_UP
return bd;
}
/**
* 将字符串数字转化为int型数字
*
* @param str被转化字符串
* @param defValue转化失败后的默认值
* @return int
*/
public static int parseInt(String str, int defValue) {
try {
return Integer.valueOf(str);
} catch (Exception e) {
return defValue;
}
}
public static long parseLong(String str, long defValue) {
try {
return Long.valueOf(str);
} catch (Exception e) {
return defValue;
}
}
public static Long strToLong(String str, Long defValue) {
try {
return Long.valueOf(str);
} catch (Exception e) {
return defValue;
}
}
/**
* 将字符串数字转化为double型数字
*
* @param str被转化字符串
* @param defValue转化失败后的默认值
* @return double
*/
public static double parseDouble(String str, double defValue) {
try {
return Double.parseDouble(str);
} catch (Exception e) {
return defValue;
}
}
/**
* 检测字符串是否为空
*/
public static boolean strIsNull(String str) {
return ((str == null) || "".equals(str) || "null".equalsIgnoreCase(str));
}
/**
* 去空格,如为null则转化为空字符串
*/
public static String trim(String str) {
if (str == null || "null".equalsIgnoreCase(str)
|| "undefined".equalsIgnoreCase(str)) {
return "";
}
return str.trim();
}
/**
* 将字符串数组转化成中间用逗号分割的字符串 "'a','b','c'"
*/
public static String getRecordIds(String[] recordIds) {
if (recordIds == null || recordIds.length == 0)
return "";
if (recordIds.length == 1)
return recordIds[0];
StringBuffer ids = new StringBuffer();
for (int i = 0; i < recordIds.length; i++) {
if (i == recordIds.length - 1) {
ids.append("'" + recordIds[i] + "'");
} else {
ids.append("'" + recordIds[i] + "'" + ",");
}
}
return ids.toString();
}
/**
* 将字符串数组转化成中间用逗号分割的字符串 "a,b,c"
*/
public static String getStrs(String[] strs) {
if (strs == null || strs.length == 0)
return "";
if (strs.length == 1)
return strs[0];
StringBuffer ids = new StringBuffer();
for (int i = 0; i < strs.length; i++) {
if (i == strs.length - 1) {
ids.append(strs[i]);
} else {
ids.append(strs[i] + ",");
}
}
return ids.toString();
}
/**
* 将字符串数组转化成中间用逗号分割的字符串 "a,b,c"
*/
public static String getStrsRep(String[] strs, String rep, String newStr) {
if (strs == null || strs.length == 0)
return "";
if (strs.length == 1)
return strs[0];
StringBuffer ids = new StringBuffer();
for (int i = 0; i < strs.length; i++) {
if (i == strs.length - 1) {
ids.append(strs[i].replace(rep, newStr));
} else {
ids.append(strs[i].replace(rep, newStr) + ",");
}
}
return ids.toString();
}
/**
* 将字符串数组转化成中间用逗号分割的字符串 "a,b,c"
*/
public static String getStrsBySplit(String[] strs, String split) {
if (strs == null || strs.length == 0)
return "";
if (strs.length == 1)
return strs[0];
StringBuffer ids = new StringBuffer();
for (int i = 0; i < strs.length; i++) {
if (i == strs.length - 1) {
ids.append(strs[i]);
} else {
ids.append(strs[i] + split);
}
}
return ids.toString();
}
/**
* 验证EMAIL方法
*
* @param str
* 被验证的email字符串
* @return 成功返回true 失败返回false
*/
public static boolean isEmail(String str) {
if (str == null)
return false;
str = str.trim();
if (str.length() < 6)
return false;
return true;
}
public static boolean isEmail(String value, String expression) {
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(value);
return matcher.find();
}
/**
* 在不足len位的数字前面自动补零
*/
public static String getLimitLenStr(String str, int len) {
if (str == null) {
return "";
}
while (str.length() < len) {
str = "0" + str;
}
return str;
}
/**
* 字符串GBK到UTF-8码的转化
*
* @param inStr
* GBK编码的字符串
* @return UTF-8编码的字符串
*/
public static String wapGbkToUtf(String inStr) {
char temChr;
int ascInt;
int i;
String result = new String("");
if (inStr == null) {
inStr = "";
}
for (i = 0; i < inStr.length(); i++) {
temChr = inStr.charAt(i);
ascInt = temChr + 0;
if (ascInt > 255) {
result = result + "&#x" + Integer.toHexString(ascInt) + ";";
} else {
result = result + temChr;
}
}
return result;
}
/**
* 特殊字符替换
*/
public static String replaceStrHtml(String inStr) {
String result = inStr;
if (result != null && !("".equals(result))) {
result = result.replaceAll("\r\n", "<br>");
result = result.replaceAll(" ", " ");
}
return result;
}
/**
* 特殊字符&替换&
*/
public static String replaceStrForWap(String inStr) {
String result = inStr;
if (!Utils.strIsNull(inStr)) {
result = result.replaceAll("&", "&");
result = result.replaceAll("&", "&");
}
return result;
}
/**
* 判断对象是否为null或""(条件成立则返回ture,否则返回false)
*
* @param objects
* @return
*/
public static boolean isObjectEmpty(Object objects) {
if (objects == null || "".equals(objects)) {
return true;
}
return false;
}
/**
* 判断对象是否不为null或""(条件成立则返回ture,否则返回false)
*
* @param objects
* @return
*/
public static boolean isObjectNotEmpty(Object objects) {
return !isObjectEmpty(objects);
}
// ------------------------------用户请求数据-----------------------------------
/**
* 得到当前请求的URL
*
* @param request
* @return
*/
public static String getActionURL(HttpServletRequest req) {
// 请求地址
String hearderString = req.getHeader("referer");
String path = req.getContextPath();
Integer port = req.getServerPort();
StringBuffer sbf = new StringBuffer();
if (port.compareTo(80) != 0) {
sbf.append(req.getScheme()).append("://")
.append(req.getServerName()).append(":")
.append(req.getServerPort() + path).append("/");
} else {
sbf.append(req.getScheme()).append("://")
.append(req.getServerName()).append(path).append("/");
}
return hearderString.substring(sbf.length());
}
/**
* 得到客户端请求IP地址
*
* @param request
* @return
*/
public static String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_CLIENT_IP");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("x-real-ip");
}
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
String[] ips = ip.split(",");
if (ips.length> 1) {
ip = ips[0];
}
return ip;
}
/***
* 获取IP
*
* @param request
* @return
*/
public static String getIp(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if (ip == null) {
ip = request.getRemoteAddr();
}
return ip;
}
// Cookie 数据获得
public static String getCookieValue(Cookie[] cookies, String str) {
String result = null;
if (Utils.isObjectNotEmpty(cookies)) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals(str)) {
result = cookie.getValue();
break;
}
}
}
return result;
}
/**
* 获取指定名字的Cookie值,找不到则返回null
*
* @return 成功返回 Cookie的值, 否则返回 null
*/
public static String getCookie(HttpServletRequest req, String cookieName) {
String result = null;
Cookie[] cookies = req.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
cookie.setPath("/");
if (cookieName.equals(cookie.getName())) {
result = cookie.getValue();
break;
}
}
}
return result;
}
/*
* // 根据Map输出JSON,返回null public static String ajaxJson(Map<String, String>
* jsonMap) { JSONObject jsonObject = JSONObject.fromObject(jsonMap); return
* ajax(jsonObject.toString(), "text/html"); }
*
* // 根据Map输出JSON,返回null public static String ajaxJsonObject(Map<String,
* Object> jsonMap) { JSONObject jsonObject =
* JSONObject.fromObject(jsonMap); return ajax(jsonObject.toString(),
* "text/html"); }
*
* // 根据Object输出JSON,返回null public static String ajaxJsonObj(Object obj) {
* JSONObject jsonObject = JSONObject.fromObject(obj); return
* ajax(jsonObject.toString(), "text/html"); }
*
* // 根据List输出JSON,返回NULL public static String ajaxJson(List list) {
* JSONArray jsonArray = new JSONArray(); if (Utils.isObjectNotEmpty(list))
* { jsonArray.addAll(list); } return ajax(jsonArray.toString(),
* "text/html"); }
*
* // AJAX输出,返回null public static String ajax(String content, String type) {
* try { HttpServletResponse response = ServletActionContext.getResponse();
* response.reset(); response.setContentType(type + ";charset=UTF-8");
* response.setHeader("Pragma", "No-cache");
* response.setHeader("Cache-Control", "no-cache");
* response.setDateHeader("Expires", 0);
* response.getWriter().write(content); response.getWriter().flush(); }
* catch (IOException e) { e.printStackTrace(); } return null; }
*/
// -------------------------日期处理----------------------------------------------
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
/**
* @param 输入日期
* @param 输入转换
* (规则)格式
* @return 返回日期字符串
*/
public static String format(Date date, String format) {
if (date == null || date.equals(""))
return null;
SimpleDateFormat sft = new SimpleDateFormat(format);
return sft.format(date);
}
/**
* @param 输入字符型日期
* ,如:2007-2-20
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
* @return 返回日期
* @throws ParseException
*/
public static Date parse(String date, String format){
SimpleDateFormat sft = new SimpleDateFormat(format);
try {
return sft.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
/**
* 得到两个日期之间的天数 time1>time2
*
* @param time1yyyy
* -MM-dd
* @param time2yyyy
* -MM-dd
* @return
* @throws ParseException
*/
public static long getQuot(String time1, String time2)
throws ParseException {
long quot = 0;
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = ft.parse(time1);
Date date2 = ft.parse(time2);
quot = date1.getTime() - date2.getTime();
quot = quot / 1000 / 60 / 60 / 24;
return quot;
}
/**
* 得到两个日期之间的天数 time1>time2
*
* @param time1yyyy
* -MM-dd
* @param time2yyyy
* -MM-dd
* @return
* @throws ParseException
*/
public static long getQuot(Date time1, Date time2) {
long quot = 0;
quot = time1.getTime() - time2.getTime();
quot = quot / 1000 / 60 / 60 / 24;
return quot;
}
/**
* 获取两个日期相差的自然天数
*/
public static Integer dateDiff(Date date1, Date date2) throws Exception{
return Integer.valueOf(getQuot(format(date1, "yyyy-MM-dd"), format(date1, "yyyy-MM-dd"))+"");
}
/**
* 得到两个年之间的年数 time1>time2
*
* @param time1
* Date
* @param time2
* Date
* @return
* @throws ParseException
*/
public static Integer getQuotAge(Date date1, Date date2)
throws ParseException {
Integer quot = 0;
// SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
// Date date1 = ft.parse( time1 );
// Date date2 = ft.parse( time2 );
quot = date1.getYear() - date2.getYear();
return quot;
}
/**
* 得到日期字符串
*
* @param time
* @return
* @throws ParseException
*/
public static String getStrDatetime(Date time) throws ParseException {
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return ft.format(time);
}
/**
* 得到日期字符串
*
* @param time
* @return
* @throws ParseException
*/
public static String getStrDayDatetime(Date time, String str)
throws ParseException {
SimpleDateFormat ft = new SimpleDateFormat(str);
String a = ft.format(time);
a = a.substring(0, 8) + "01";
return a;
}
/**
* 获得系统当前时间,以分隔符"-"分开
*
* @return返回当前系统日期 如:当前时间是2007年10月15日 则通过该函数得到的字符串为"2007-10-15"
*/
public String getToday() {
GregorianCalendar gc = new GregorianCalendar();
return this.format(gc.getTime(), "yyyy-MM-dd");
}
/**
* 获得系统当前时间,以分隔符"-"分开
*
* @return返回当前系统时间 如:当前时间是2007年10月15日21点45分25秒
* 则通过该函数得到的字符串为"2007-10-15-21-45-25"
*/
public String getTimeNoSeparate() {
GregorianCalendar gc = new GregorianCalendar();
return this.format(gc.getTime(), "yyyy-MM-dd-HH-mm-ss");
}
/**
* 获得当前系统时间字符串
*
* @return 返回当前系统时间字符串,精确到秒 如:当前时间是2007年10月15日21点45分25秒
* 则通过该函数得到的字符串为"20071015214525"
*/
public static String getTime() {
GregorianCalendar gc = new GregorianCalendar();
return format(gc.getTime(), "yyyyMMddHHmmss");
}
/**
* 获得当前日期字符串,格式:20071015
*
* @return 当前日期字符串
*/
public String getNow() {
GregorianCalendar gc = new GregorianCalendar();
return this.format(gc.getTime(), "yyyyMMdd");
}
/**
* 获得当前日期Date
*
* @return Date
*/
public Date getDate() {
GregorianCalendar gc = new GregorianCalendar();
return gc.getTime();
}
/**
* 得到当前时间加上多少分钟以后的时间
*
* @param minute
* @return
*/
public long getTimeMillisOfAddMinute(Long num, int minute) {
Long t = num + minute * 1000 * 60;
return t;
}
/**
* 获得当前时间Timestamp类型
*/
public static Timestamp getNowTime() {
GregorianCalendar gc = new GregorianCalendar();
Timestamp time = new Timestamp(gc.getTimeInMillis());
return time;
}
/**
* @param 输入字符型日期
* ,如:2007-2-20
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
* @return 返回日期
*/
public static Date format(String str, String format) {
Date result = null;
try {
str += " ";
int endStr = str.indexOf(" ");
String dateString = str.substring(0, endStr);
result = parse(dateString, format);
} catch (Exception ex) {
ex.printStackTrace();
}
return result;
}
/**
* 得到当前时间
*
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public String getNow(String format) {
Calendar cal = Calendar.getInstance();
return this.format(cal.getTime(), format);
}
/**
* 得到多少天以前的日期(负数表示多少天以后的日期)
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public String getDayNumOfDate(int dayNum, String format) {
int day = -dayNum;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day);
return this.format(cal.getTime(), format);
}
/**
* 得到多少天以前的日期(负数表示多少天以后的日期)
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public static Date getDayNumOfDate(int dayNum) {
int day = -dayNum;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, day);
return cal.getTime();
}
/**
* 得到指定的日期以前多少天
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public static String getDayNumOfAppointDate(Date appointDate, int dayNum,
String format) {
Calendar cal = Calendar.getInstance();
cal.setTime(appointDate);
cal.add(Calendar.DATE, -dayNum);
return format(cal.getTime(), format);
}
/**
* 得到指定的日期以前多少天
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public static Date getDayNumOfAppointDate(Date appointDate, int dayNum) {
Calendar cal = Calendar.getInstance();
cal.setTime(appointDate);
cal.add(Calendar.DATE, -dayNum);
return cal.getTime();
}
/**
* 得到指定的日期以前多少天
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public String getMonthNumOfAppointDate(Date appointDate, int monthNum,
String format) {
Calendar cal = Calendar.getInstance();
cal.setTime(appointDate);
cal.add(Calendar.MONTH, -monthNum);
return this.format(cal.getTime(), format);
}
/**
* 根据指定的日期得到多少个月以前的日期
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public static Date getMonthNumOfAppointDate(Date appointDate, int monthNum) {
Calendar cal = Calendar.getInstance();
cal.setTime(appointDate);
cal.add(Calendar.MONTH, -monthNum);
return cal.getTime();
}
/**
* 根据指定的日期得到多少个月以后的日期
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public static Date getMonthNumOfDate(Date appointDate, int monthNum) {
Calendar cal = Calendar.getInstance();
cal.setTime(appointDate);
cal.add(Calendar.MONTH, monthNum);
return cal.getTime();
}
/**
* 得到多少月以前的日期
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public String getMonthNumOfMonth(int monthNum, String format) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, monthNum);
return this.format(cal.getTime(), format);
}
/**
* 得到多少月以前的日期
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public String getMonthNumOfMonth(int monthNum, int dateNum, String format) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -monthNum);
cal.add(Calendar.DATE, -dateNum);
return this.format(cal.getTime(), format);
}
/**
* 得到多少月以前的日期
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public Date getMonthNumOfMonth1(int monthNum, int dateNum, String format) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -monthNum);
cal.add(Calendar.DATE, -dateNum);
return cal.getTime();
}
/**
* 得到多少年以前的日期
*
* @param输入int型
* @param 输入字符型日期的排列规则
* ,如:yyyy-MM-dd,MM/dd/yyyy. 根据上述输入字符型日期,此处应填写的规则是:yyyy-MM-dd
*/
public String getYearNumOfYear(int yearNum, String format) {
int year = -yearNum;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.YEAR, year);
return this.format(cal.getTime(), format);
}
// /**
// * 得到今天是当月的第几周 (一周的第一天是 周日)
// *
// * @param format
// * @return
// */
// public static int getWeekOfMonth() {
// GregorianCalendar calendar = new GregorianCalendar();
// return calendar.get(Calendar.WEEK_OF_MONTH);
// }
/**
* 判断
* 当前时间 和 指定本月第n天是否在本月同一周
* @param format
* @return
*/
public static boolean nowTodayWeekOfMonth(String value) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.add(Calendar.DAY_OF_MONTH, -1);
int j = calendar.get(Calendar.WEEK_OF_MONTH);
calendar.set(calendar.DAY_OF_MONTH, Integer.parseInt(value));
calendar.add(Calendar.DAY_OF_MONTH, -1);
int k = calendar.get(Calendar.WEEK_OF_MONTH);
return j==k;
}
/**
* 得到上一月的第一天
*
* @param format
* @return
*/
public String getStartOfLastMonth(String format) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1);
cal.set(Calendar.DATE, 1);
return this.format(cal.getTime(), format);
}
/**
* 得到第num个月后的第一天(负数表示前,正为后)
*
* @param format
* @return
*/
public String getStartOfMonth(int num, String format) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, num);
cal.set(Calendar.DATE, 1);
return this.format(cal.getTime(), format);
}
/**
* 获取当月第一天 00:00:00
*/
public static Date getStartTimeThisMon(){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY,0);
cal.set(Calendar.MINUTE,0);
cal.set(Calendar.SECOND,0);
cal.set(Calendar.MILLISECOND,0);
return cal.getTime();
}
/**
* 获取当月最后一天 23:59:59
*/
public static Date getEndTimeThisMon(){
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, 1); //加一个月
cal.set(Calendar.DATE, 1); //设置为该月第一天
cal.add(Calendar.DATE, -1); //再减一天即为上个月最后一天
cal.set(Calendar.HOUR_OF_DAY,23);
cal.set(Calendar.MINUTE,59);
cal.set(Calendar.SECOND,59);
cal.set(Calendar.MILLISECOND,999);
return cal.getTime();
}
public static void main(String[] args) {
System.out.println(format(getStartTimeThisMon(), "yyyy-MM-dd HH:mm:ss"));
System.out.println(format(getEndTimeThisMon(), "yyyy-MM-dd HH:mm:ss"));
}
/**
* 得到当月的第一天
*
* @param format
* @return
*/
public static String getStartOfMonth(String format) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, 1);
return format(cal.getTime(), format);
}
/**
* 得到当月的最后一天
*
* @param format
* @return
*/
public static String getEndOfMonth(String format) {
Calendar ca = Calendar.getInstance();
ca.set(Calendar.DAY_OF_MONTH,
ca.getActualMaximum(Calendar.DAY_OF_MONTH));
return format(ca.getTime(), format);
}
/**
* 得到前月的后一天
*
* @param format
* @return
*/
public static String getEndOfPreMonth(String format) {
Calendar cale = Calendar.getInstance();
cale.set(Calendar.DAY_OF_MONTH, 0);// 设置为1号,当前日期既为本月第一天
return format(cale.getTime(), format);
}
/**
* 得到前月的前一天
*
* @param format
* @return
*/
public static String getStartOfPreMonth(String format) {
Calendar cal = Calendar.getInstance();// 获取当前日期
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天
return format(cal.getTime(), format);
}
/**
* 得到当月的第一天
*
* @param format
* @return
*/
public String getStartOfMonth_test(String format) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DATE, 1);
return this.format(cal.getTime(), format);
}
/**
* 得到下一月的第一天
*
* @param format
* @return
*/
public String getStartOfNextMonth(String format) {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1);
cal.set(Calendar.DATE, 1);
return this.format(cal.getTime(), format);
}
/**
* 加一年
*
* @return
*/
public String getYears() {
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(gc.getTime());
gc.add(1, +1);
gc.set(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH),
gc.get(Calendar.DATE));
return sf.format(gc.getTime());
}
/**
* 加半年
*
* @return
*/
public String getHalfYear() {
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(gc.getTime());
gc.add(2, +6);
gc.set(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH),
gc.get(Calendar.DATE));
return sf.format(gc.getTime());
}
/**
* 加一个季度
*
* @return
*/
public String getQuarters() {
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(gc.getTime());
gc.add(2, +3);
gc.set(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH),
gc.get(Calendar.DATE));
return sf.format(gc.getTime());
}
/**
* 返回yyyy-MM-dd格式的字符串
*
* @return
*/
public static String getLocalDate() {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar gc = new GregorianCalendar();
return df.format(gc.getTime());
}
/**
* 日期转换("yyyy-MM-dd")
*/
public static final Date parseDate(String dateStr) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
return df.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 日期转换("yyyy-MM-dd")
*/
public static final Date parseDate(String dateStr, String format) {
SimpleDateFormat df = new SimpleDateFormat(format);
try {
return df.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/**
* 返回yyyy-MM-dd格式的字符串
*
* @return
*/
public static String getparseDate(Date dateStr, String format) {
SimpleDateFormat df = new SimpleDateFormat(format);
Calendar cal = Calendar.getInstance();
cal.setTime(dateStr);
return df.format(cal.getTime());
}
/**
* 判断两个日期的先后顺序
*
* @param dt1
* @param dt2
* @return
*/
public static int compare_date(Date dt1, Date dt2) {
try {
if (dt1.getTime() > dt2.getTime()) {
return 1;
} else if (dt1.getTime() <= dt2.getTime()) {
return -1;
} else {
return 0;
}
} catch (Exception exception) {
exception.printStackTrace();
}
return 0;
}
/**
* 得到两个时间的秒数差 date1 - date2
* @param date1
* @param date2
* @return
*/
public static int getDateSecondsSub(String date1, String date2){
long a = parseDate(date1, "yyyy-MM-dd HH:mm:ss").getTime();
long b = parseDate(date2, "yyyy-MM-dd HH:mm:ss").getTime();
int c = (int)((a - b) / 1000);
return c;
}
/**
* 按照概率生成对应的随机数 <br>
* 例如: int[] arr = {70, 20, 10} 生成的随机数:0(概率为70%) 生成的随机数:1(概率为20%)
* 生成的随机数:2(概率为10%)
*
* @param arr
* @return i 返回下标: 0,1,2 ...
*/
public static int weightRandom(Integer[] arr) {
int x = (int) (Math.random() * 100);
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
if (sum > x) {
return i;
}
}
return -1;
}
/****
* 验证 Integer类型
*
* @param i
* @return
*/
public static boolean isBlank(Integer i) {
if (i == null) {
return true;
}
return false;
}
public static BigDecimal doubleToBigDecimal(Double d) {
try {
return new BigDecimal(d.toString());
} catch (Exception e) {
return new BigDecimal("0");
}
}
/***
* l == null || l.size() <= 0 返回 true
*
* @param l
* @return
*/
public static boolean isEmptyList(List<?> l) {
if (l == null || l.size() <= 0) {
return true;
}
return false;
}
/**
* 提供精确的加法运算。
*
* @param v1
* 被加数
* @param v2
* 加数
* @return 两个参数的和
*/
public static double add(double v1, double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return (b1.add(b2)).doubleValue();
}
/**
* 提供精确的减法运算。
*
* @param v1
* 被减数
* @param v2
* 减数
* @return 两个参数的差
*/
public static double sub(double v1, double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return (b1.subtract(b2)).doubleValue();
}
/**
* 提供精确的乘法运算。
*
* @param v1
* 被乘数
* @param v2
* 乘数
* @return 两个参数的积
*/
public static double mul(double v1, double v2) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return (b1.multiply(b2)).doubleValue();
}
/**
* 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
*
* @param v1
* 被除数
* @param v2
* 除数
* @param scale
* 表示需要精确到小数点以后几位。
* @return 两个参数的商
*/
public static double div(double v1, double v2, int scale) {
if (scale < 0) {
System.err.println("除法精度必须大于0!");
return 0;
}
BigDecimal b1 = new BigDecimal(Double.toString(v1));
BigDecimal b2 = new BigDecimal(Double.toString(v2));
return (b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP)).doubleValue();
}
/***
* 获得当前时间和传入时间相隔的秒数
* */
public static long getSpacing(Date date1) {
Date date = new Date();
return (date.getTime() - date1.getTime()) / 1000;
}
/**
* 整理数据Double的小数位数
* */
public static double getDoubleByScale(Double v1, int scale) {
BigDecimal b1 = new BigDecimal(Double.toString(v1));
return b1.setScale(scale, BigDecimal.ROUND_HALF_UP).doubleValue();
}
/****
* 获取指定日期 minute分钟后的时间
*
* @param date
* @param hour
* @return
*/
public static Date getTimeAfterMinute(Date date, int minute) {
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + minute);
return c.getTime();
}
public static boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
}
/***
* 判断是否是英文
*
* @param strName
*/
public static boolean isChinese(String strName) {
char[] ch = strName.toCharArray();
for (int i = 0; i < ch.length;) {
char c = ch[i];
if (isChinese(c) == true) {
return true;
} else {
return false;
}
}
return false;
}
/**
* @param s
* @return
*/
public static String toUTF8String(String s) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c >= 0 && c <= 255) {
sb.append(c);
} else {
byte[] b;
try {
b = Character.toString(c).getBytes("utf-8");
} catch (Exception ex) {
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0)
k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return sb.toString();
}
/**
* 数字金额大写转换,思想先写个完整的然后将如零拾替换成零 要用到正则表达式
*/
public static String digitUppercase(double n) {
String fraction[] = { "角", "分" };
String digit[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
String unit[][] = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } };
String head = n < 0 ? "负" : "";
n = Math.abs(n);
String s = "";
for (int i = 0; i < fraction.length; i++) {
s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i])
.replaceAll("(零.)+", "");
}
if (s.length() < 1) {
s = "整";
}
int integerPart = (int) Math.floor(n);
for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
String p = "";
for (int j = 0; j < unit[1].length && n > 0; j++) {
p = digit[integerPart % 10] + unit[1][j] + p;
integerPart = integerPart / 10;
}
s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i]
+ s;
}
return head
+ s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "")
.replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
}
/**
* 获得配置文件所在目录<br>
*
* @param file
* @return
*/
public static File getResource(String file) {
URL url = Utils.class.getResource("");
String pkg = "";
if (Utils.class.getPackage() != null) {
pkg = Utils.class.getPackage().getName();
}
String path = url.getPath();
path = path.substring(0, path.length() - pkg.length() - 1);
String fileSeparator = System.getProperty("link.properties");
File rtn = new File(path + fileSeparator + file.trim());
return rtn;
}
public static String getMacAddr() {
String MacAddr = "";
try {
Enumeration<NetworkInterface> em = NetworkInterface
.getNetworkInterfaces();
while (em.hasMoreElements()) {
NetworkInterface nic = em.nextElement();
byte[] b = nic.getHardwareAddress();
if (b == null) {
continue;
}
for (int i = 0; i < b.length; i++) {
}
}
} catch (SocketException e) {
e.printStackTrace();
System.exit(-1);
}
return MacAddr;
}
public static String getLocalIP() {
String ip = "";
try {
Enumeration<?> e1 = (Enumeration<?>) NetworkInterface
.getNetworkInterfaces();
while (e1.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) e1.nextElement();
Enumeration<?> e2 = ni.getInetAddresses();
while (e2.hasMoreElements()) {
InetAddress ia = (InetAddress) e2.nextElement();
ip = ia.getHostAddress();
}
}
} catch (SocketException e) {
e.printStackTrace();
System.exit(-1);
}
return ip;
}
/* 一个将字节转化为十六进制ASSIC码的函数 */
public static String byteHEX(byte ib) {
char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
'b', 'c', 'd', 'e', 'f' };
char[] ob = new char[2];
ob[0] = Digit[(ib >>> 4) & 0X0F];
ob[1] = Digit[ib & 0X0F];
String s = new String(ob);
return s;
}
/****
* 获取数组值
*
* @param array
* @param index
* @return
*/
public static String getArrayValue(String[] array, int index) {
try {
return array[index];
} catch (Exception e) {
return "";
}
}
public static String md5ByHex(String src) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte b[] = src.getBytes();
md.reset();
md.update(b);
byte hash[] = md.digest();
String hs = "";
String stmp = "";
for (int i = 0; i < hash.length; i++) {
stmp = Integer.toHexString(hash[i] & 0xff);
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs.toUpperCase();
} catch (Exception e) {
return "";
}
}
public static long strToLong(String str) {
try {
return Long.valueOf(str);
} catch (Exception e) {
return 0L;
}
}
public static String UrlDecode(String param) {
try {
return URLDecoder.decode(param, "UTF-8");
} catch (UnsupportedEncodingException e) {
return "";
}
}
// 保持长度 替换最后一个元素
public static String[] repArray(String[] array, String newStr, int len) {
if (array == null || array.length <= 0) {
return new String[] { newStr };
}
List<String> list = new ArrayList<String>();
list.add(newStr);
for (int i = 0; i < array.length; i++) {
if (list.size() >= len) {
break;
}
if (!array[i].equals(newStr)) {
list.add(array[i]);
}
}
return list.toArray(new String[list.size()]);
}
public static String[] repArrayStr(String[] array) {
if (array == null || array.length <= 0) {
return array;
} else {
for (int i = 0; i < array.length; i++) {
array[0] = array[0].split("_")[0];
}
return array;
}
}
/****
* 数组分页
*
* @param strs
* 数组集合(ids)
* @param pageSize
* 每页显示数
* @param toPage
* 当前页
* @param order
* 排序 0 asc 1 desc
* @return
*/
public static String[] getArray(String[] strs, int pageSize, int toPage,
int order) {
if (strs == null) {
return new String[] {};
}
if (order == 1) {
strs = arraySort(strs);
}
int start = 0;
int end = 0;
end = toPage * pageSize;
if (end >= strs.length) {
end = strs.length - start;
}
start = (toPage - 1) * pageSize;
if (start > strs.length) {
return new String[] {};
}
String[] ns = new String[(end - start)];
System.arraycopy(strs, start, ns, 0, (end - start));
return ns;
}
/***
* 数组倒序
*
* @param strs
* @return
*/
public static String[] arraySort(String[] strs) {
if (strs == null || strs.length <= 0) {
return new String[] {};
}
String[] newstr = new String[strs.length];
int len = 0;
for (int i = strs.length - 1; i >= 0; i--) {
newstr[len] = strs[i];
len++;
}
return newstr;
}
/**
* 是否是数字
*/
public static boolean isNumber(String str) {
if (StringUtils.isEmpty(str)) {
return false;
}
char[] chars = str.toCharArray();
int sz = chars.length;
boolean hasExp = false;
boolean hasDecPoint = false;
boolean allowSigns = false;
boolean foundDigit = false;
int start = (chars[0] == '-') ? 1 : 0;
if (sz > start + 1) {
if (chars[start] == '0' && chars[start + 1] == 'x') {
int i = start + 2;
if (i == sz) {
return false; // str == "0x"
}
for (; i < chars.length; i++) {
if ((chars[i] < '0' || chars[i] > '9')
&& (chars[i] < 'a' || chars[i] > 'f')
&& (chars[i] < 'A' || chars[i] > 'F')) {
return false;
}
}
return true;
}
}
sz--;
int i = start;
while (i < sz || (i < sz + 1 && allowSigns && !foundDigit)) {
if (chars[i] >= '0' && chars[i] <= '9') {
foundDigit = true;
allowSigns = false;
} else if (chars[i] == '.') {
if (hasDecPoint || hasExp) {
return false;
}
hasDecPoint = true;
} else if (chars[i] == 'e' || chars[i] == 'E') {
if (hasExp) {
return false;
}
if (!foundDigit) {
return false;
}
hasExp = true;
allowSigns = true;
} else if (chars[i] == '+' || chars[i] == '-') {
if (!allowSigns) {
return false;
}
allowSigns = false;
foundDigit = false;
} else {
return false;
}
i++;
}
if (i < chars.length) {
if (chars[i] >= '0' && chars[i] <= '9') {
return true;
}
if (chars[i] == 'e' || chars[i] == 'E') {
return false;
}
if (!allowSigns
&& (chars[i] == 'd' || chars[i] == 'D' || chars[i] == 'f' || chars[i] == 'F')) {
return foundDigit;
}
if (chars[i] == 'l' || chars[i] == 'L') {
return foundDigit && !hasExp;
}
return false;
}
return !allowSigns && foundDigit;
}
/** 差集 */
public static Set<String> difference(Set<String> setA, Set<String> setB) {
Set<String> setDifference = new HashSet<String>();
String s = "";
Iterator<String> iterA = setA.iterator();
while (iterA.hasNext()) {
s = iterA.next();
if (!setB.contains(s)) {
setDifference.add(s);
}
}
return setDifference;
}
public static String[] sort(String[] list) {
for (int i = 0; i < list.length - 1; i++) {
for (int j = 1; j < list.length - i; j++) {
Integer a;
if ((Integer.valueOf(list[j - 1].trim())).compareTo(Integer
.valueOf(list[j].trim())) > 0) { // 比较两个整数的大小
a = Integer.valueOf(list[j - 1].trim());
list[j - 1] = list[j].trim();
list[j] = a.toString();
}
}
}
return list;
}
/**
* left-right的秒数
*
* @author 彭堃(penkee@163.com), 2013-10-11
*
*/
public static long calDateSecondVariation(Date left, Date right) {
long diff = left.getTime() - right.getTime();
return diff / 1000;
}
/**
* 返回小数点后2位
*
* @param object
* @return .00
*/
public static BigDecimal setScaleBidDecimal(BigDecimal bd) {
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); // 取小数点后2位 /ROUND_HALF_UP
return bd;
}
/**
* 汉字转拼音的方法
*
* @param name
* 汉字
* @return 拼音
*/
/*
* public static String getHanyuToPinyin(String name){ String pinyinName =
* ""; char[] nameChar = name.toCharArray(); HanyuPinyinOutputFormat
* defaultFormat = new HanyuPinyinOutputFormat();
* defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
* defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); for (int i =
* 0; i < nameChar.length; i++) { if (nameChar[i] > 128) { try { pinyinName
* += PinyinHelper.toHanyuPinyinStringArray (nameChar[i], defaultFormat)[0];
* } catch (BadHanyuPinyinOutputFormatCombination e) { e.printStackTrace();
* } } } return pinyinName; }
*/
/**
* 随机返回一个小写字母
*
* @author liuy
* @return
* @return String
* @date 2014-3-10 下午5:58:52
*/
public static String getRecoNamemcod() {
//
// MassegeUtil.setLength(4);
String name = "";
Map<String, Object> param = new HashMap<String, Object>();
String[] beforeShuffle = new String[] { "a", "b", "c", "d", "e", "f",
"g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z" };
Random rd = new Random();
name = beforeShuffle[rd.nextInt(24)]; // 字母
return name;
}
/**
* 返回4个随机数
*
* @author liuy
* @return
* @return String
* @date 2014-3-10 下午5:58:06
*/
public static String getRandomNumber() {
StringBuilder randnum = new StringBuilder();// 验证码
// String[] c=new String[]{"2","3","4","5","6","7","8","9","6","8"};
for (int i = 0; i < 4; i++) {
Random rd = new Random();
int index = rd.nextInt(10);
do {
index = rd.nextInt(10);
} while (index == 0 || index == 1);
randnum.append(index);
}
return randnum.toString();
}
/**
* 返回6个随机数
*
* @author liuy
* @return
* @return String
* @date 2014-3-10 下午5:58:06
*/
public static String getRandomNumber6() {
StringBuilder randnum = new StringBuilder();// 验证码
// String[] c=new String[]{"2","3","4","5","6","7","8","9","6","8"};
for (int i = 0; i < 6; i++) {
Random rd = new Random();
int index = rd.nextInt(10);
do {
index = rd.nextInt(10);
} while (index == 0 || index == 1);
randnum.append(index);
}
return randnum.toString();
}
/**
* 判断是否为汉子
*
* @author liuy
* @return
* @return boolean
* @date 2014-3-10 下午6:36:51
*/
public static boolean getPatternHanzi(String str) {
Pattern p_str = Pattern.compile("[\\u4e00-\\u9fa5]+");
// String str="xzzc我是汉字";
Matcher m = p_str.matcher(str);
if (m.find() && m.group(0).equals(str)) {
// OK 是汉字
return true;
}
return false;
}
/**
* @about chengy
* @param str
* @return
* @date 2014-3-13 上午11:36:45 根据"$"符号切割字符串,返回一个字符串数组
*/
public static String[] subStringBY(String str) {
String[] a = str.split("\\$");
String[] strs = new String[a.length];
for (int i = 0; i < a.length; i++) {
strs[i] = a[i];
}
return strs;
}
public static BigDecimal getVipAmount(Integer vipLevel) {
if (vipLevel == 1) {
return new BigDecimal("100");
} else if (vipLevel == 2) {
return new BigDecimal("300");
} else if (vipLevel == 3) {
return new BigDecimal("500");
} else {
return BigDecimal.ZERO;
}
}
/**
* 输出JSON数据
* @param str
* @param response
* @param contextType
*/
public static void outJsonStr(String str,HttpServletResponse response,String contextType){
response.setContentType(contextType);
try {
response.getWriter().print(str);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 过滤html标签
* @param str
* @return
*/
public static String stripHtmlLabel(String str) {
if(Utils.strIsNull(str)){
return str;
}
str = str.replaceAll("<.*?>", "").replaceAll("\r\n", "");
return str;
}
/**
* 从map中取值赋值给对象
* @param obj 要赋值的对象
* @param map 数据源
*/
public static void getObjectFromMap(Object obj, Map<String,Object> map){
Class<?> cla = obj.getClass();//获得对象类型
Field field[] = cla.getDeclaredFields();//获得该类型中的所有属性
for(int i=0;i<field.length;i++) {//遍历属性列表
field[i].setAccessible(true);//禁用访问控制检查
Class<?> fieldType = field[i].getType();//获得属性类型
String attr = map.get(field[i].getName())==null?null:map.get(field[i].getName()).toString();//获得属性值
if(attr==null) {//如果属性值为null则不做任何处理,直接进入下一轮循环
continue;
}
/**
* 根据对象中属性类型的不同,将request对象中的字符串转换为相应的属性
*/
try {;
if(fieldType==String.class) {
field[i].set(obj,new String(attr));
}
else if(fieldType==Integer.class){//当转换失败时,设置0
field[i].set(obj,new Integer(attr));
}
else if(fieldType==Date.class) {//当转换失败时,设置为null
field[i].set(obj,new Date(attr));
}
else if(fieldType==BigDecimal.class) {//当转换失败时,设置为null
field[i].set(obj,new BigDecimal(attr));
}else if(fieldType==Short.class){
field[i].set(obj,new Short(attr));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 比较版本号的大小,前者大则返回一个正数,后者大返回一个负数,相等则返回0
* @param version1
* @param version2
* @return
*/
public static int compareVersion(String version1, String version2){
String[] versionArray1 = version1.split("\\.");//注意此处为正则匹配,不能用".";
String[] versionArray2 = version2.split("\\.");
int idx = 0;
int minLength = Math.min(versionArray1.length, versionArray2.length);//取最小长度值
int diff = 0;
while (idx < minLength
&& (diff = versionArray1[idx].length() - versionArray2[idx].length()) == 0//先比较长度
&& (diff = versionArray1[idx].compareTo(versionArray2[idx])) == 0) {//再比较字符
++idx;
}
//如果已经分出大小,则直接返回,如果未分出大小,则再比较位数,有子版本的为大;
diff = (diff != 0) ? diff : versionArray1.length - versionArray2.length;
return diff;
}
/**
* String[]转int[]
* @param str
* @return
*/
public static Integer[] StringConvertInteger(String[] str){
Integer[] ig = new Integer[str.length];
for(int i=0;i<str.length;i++){
ig[i]=Integer.parseInt(str[i]);
}
return ig;
}
public static Map getParameterMap(HttpServletRequest request) {
// 参数Map
Map properties = request.getParameterMap();
// 返回值Map
Map returnMap = new HashMap();
Iterator entries = properties.entrySet().iterator();
Map.Entry entry;
String name = "";
String value = "";
while (entries.hasNext()) {
entry = (Map.Entry) entries.next();
name = (String) entry.getKey();
Object valueObj = entry.getValue();
if(null == valueObj){
value = "";
}else if(valueObj instanceof String[]){
String[] values = (String[])valueObj;
for(int i=0;i<values.length;i++){
value = values[i] + ",";
}
value = value.substring(0, value.length()-1);
}else{
value = valueObj.toString();
}
returnMap.put(name, value);
}
return returnMap;
}
public static int daysBetween(int counts,Date stime,Date etime) throws ParseException{
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
String smdate = sft.format(stime);
String bdate = sft.format(new Date());
if(Utils.isObjectNotEmpty(etime)){
bdate = sft.format(etime);
}
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));
cal.add(Calendar.DATE, counts);
long time2 = cal.getTimeInMillis();
long between_days=(time2-time1)/(1000*3600*24);
return Integer.parseInt(String.valueOf(between_days));
}
/**
* 判断是否在 0 点前minutes[0],后 minutes[1] 分钟, minutes[0] < 60 , minutes[1] < 60
* @param now
* @param minutes
* @return
*/
public static boolean nearDawnMinutes(Date now,String[] minutes){
boolean b = false;
try {
if(minutes != null && minutes.length==2){
Integer minute0 = Integer.valueOf(minutes[0]);
Integer minute1 = Integer.valueOf(minutes[1]);
if(Utils.isObjectNotEmpty(now) && minute0 <60 && minute1 < 60){
int nowHour = now.getHours();
int nowMinute = now.getMinutes();
if((nowHour == 23 && minute0>= 60-nowMinute) || ( nowHour ==0 && nowMinute<=minute1) ){
b = true;
}
}
}
} catch (Exception e) {
b = false;
}
return b;
}
/**
* 时间戳格式化
*/
public static String toString(String dateTime,String format){
SimpleDateFormat sdf=new SimpleDateFormat(format);
String sd = sdf.format(new Date(Long.parseLong(dateTime))); // 时间戳转换成时间
return sd;
}
}
\ No newline at end of file
package com.chineseall.djgdata.common.vo;
import lombok.Data;
import java.io.Serializable;
/**
* Created by yuchunlin on 2019/5/28.
*/
@Data
public class ClientItem implements Serializable{
private String clientName;
private String clientId;
private String clientSecret;
}
package com.chineseall.djgdata.common.vo;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Created by yuchunlin on 2019/5/28.
*/
@Data
@Component
@ConfigurationProperties(prefix = "oauthclient")
public class OauthClient {
private List<ClientItem> clients;
}
package com.chineseall.djgdata.common.vo;
import cn.sh.chineseall.framework.api.MapMessage;
import com.chineseall.djgdata.common.enums.ResultEnum;
/**
* 统一消息返回,<br>
* 目前只做错误消息返回
*
* @author yuchunlin
*/
public class TechMessage<T> extends MapMessage {
public Integer getCode() {
return (Integer) this.get("code");
}
public void setCode(Integer code) {
this.set("code", code);
}
public String getMsg() {
return (String) this.get("msg");
}
public void setMsg(String msg) {
this.set("msg", msg);
}
public T getData() {
return (T) this.get("data");
}
public void setData(T data) {
if (null != data){
this.put("data", data);
}
}
public TechMessage() {
this(ResultEnum.Success);
}
public TechMessage(Integer code, String msg) {
ResultEnum resultEnum = ResultEnum.findResultEnum(code);
if (resultEnum == ResultEnum.Success){
super.setSuccess(true);
}else {
super.setSuccess(false);
}
this.setCode(code);
this.setMsg(msg);
this.setInfo(msg);
}
public TechMessage(ResultEnum result) {
this(result.getCode(), result.getMessage());
}
public TechMessage(Integer code, String msg, T data) {
this(code, msg);
this.setData(data);
}
public TechMessage(ResultEnum result, T data) {
this(result);
this.setData(data);
}
}
package com.chineseall.djgdata.dao;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort;
import cn.sh.chineseall.framework.core.util.CollectionUtils;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.JobRecord;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@Component
public class JobRecordDao extends AlphaStaticJdbcDao<JobRecord, Long> {
@Override
protected void calculateCacheDimensions(JobRecord convertLogJobRecord, Collection<String> collection) {
}
public JobRecord queryLastRecord(){
Criteria criteria = new Criteria();
Sort s = new Sort(Sort.Direction.DESC, "begin_time");
Query query = new Query(criteria);
query.with(s);
List<JobRecord> result = query(query);
if(CollectionUtils.isEmpty(result))
return null;
return result.get(0);
}
public Long countRecordByBeginTime(String jobName, Date beginTime){
Criteria criteria = Criteria.where("job_name").is(jobName).and("begin_time").lte(beginTime).and("end_time").gt(beginTime).and("success").is(true);
return count(new Query(criteria));
}
public Long countRecordByEndTime(String jobName, Date endTime){
Criteria criteria = Criteria.where("job_name").is(jobName).and("begin_time").lt(endTime).and("end_time").gte(endTime).and("success").is(true);
return count(new Query(criteria));
}
}
package com.chineseall.djgdata.dao;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import cn.sh.chineseall.framework.dao.mysql.sql.factory.AlphaSqlFactory;
import cn.sh.chineseall.framework.dao.mysql.sql.template.AlphaSql;
import cn.sh.chineseall.framework.dao.mysql.sql.template.AlphaSqlBuilder;
import com.chineseall.djgdata.model.ReadingBaseInfo;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class ReadingBaseInfoDao extends AlphaStaticJdbcDao<ReadingBaseInfo, Long> {
@Override
protected void calculateCacheDimensions(ReadingBaseInfo readingBaseInfo, Collection<String> collection) {
}
public Long countByTime(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("create_time").gte(beginTime).lt(endTime);
return count(new Query(criteria));
}
public ReadingBaseInfo queryDataByTimeFirst(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("create_time").gte(beginTime).lt(endTime);
return query(new Query(criteria).with(new Sort(Sort.Direction.ASC, "create_time")).limit(1)).stream().findFirst().orElse(null);
}
public ReadingBaseInfo queryDataByTimeLast(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("create_time").gte(beginTime).lt(endTime);
return query(new Query(criteria).with(new Sort(Sort.Direction.DESC, "create_time")).limit(1)).stream().findFirst().orElse(null);
}
public List<LinkedHashMap> queryRauthCount(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select user_id,region_code,left(`timestamp`,7) date6,SUBSTR(`timestamp`,6,2) mon ,author,count(*) cc from reading_data ");
sql.append(" where user_id is not null and author is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY user_id,left(`timestamp`,7),author ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRreadComp(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select user_id,real_name,left(`timestamp`,7) date6,SUBSTR(`timestamp`,6,2) mon,(case book_type_code when 'DIGITAL' then 1 else 2 end ) book_type,count(*) cc from reading_data ");
sql.append(" where user_id is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY user_id,left(`timestamp`,7),book_type_code ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRpublishingCount(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select user_id,left(`timestamp`,7) date6,SUBSTR(`timestamp`,6,2) mon,pub_name,count(*) cc from reading_data ");
sql.append(" where user_id is not null and pub_name is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY user_id,left(`timestamp`,7),pub_name ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRtypeCount(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select user_id,region_code,left(`timestamp`,7) date6,SUBSTR(`timestamp`,6,2) mon,left(clc_code,1) type,count(*) cc from reading_data ");
sql.append(" where user_id is not null and clc_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY user_id,left(`timestamp`,7),left(clc_code,1) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookRate(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select left(clc_code,1) clc_code,left(`timestamp`,4) year,count(*) cc,client_id from reading_data ");
sql.append(" where clc_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY left(clc_code,1),left(`timestamp`,4) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulZttrend(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select left(clc_code,1) clc_code,left(`timestamp`,4) year,SUBSTR(`timestamp`,6,2) mon,count(*) cc,client_id from reading_data ");
sql.append(" where clc_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY left(clc_code,1),left(`timestamp`,4),SUBSTR(`timestamp`,6,2) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulPub(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select pub_code,pub_name,left(`timestamp`,7) date6,count(*) cc,client_id from reading_data ");
sql.append(" where pub_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime and verb_name<>'归还' ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY pub_code,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulPubtrend(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select pub_code,pub_name,left(`timestamp`,4) year,SUBSTR(`timestamp`,6,2) mon,count(*) cc,client_id from reading_data ");
sql.append(" where pub_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY pub_code,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookStar(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select region_code,region_name,user_id,real_name,left(`timestamp`,4) date6,count(*) cc,client_id from reading_data");
sql.append(" where user_id is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY user_id,left(`timestamp`,4) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookBooks(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select region_code,region_name,school_id,school_name,left(`timestamp`,7) date6,count(*) cc,client_id from reading_data ");
sql.append(" where school_id is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY school_id,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookYtrend(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select region_code,region_name,left(`timestamp`,4) year,count(*) cc,client_id from reading_data ");
sql.append(" where region_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY region_code,left(`timestamp`,4) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookMtrend(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select grade_code,grade_name,region_code,region_name,left(`timestamp`,4) year,SUBSTR(`timestamp`,6,2) mon,count(*) cc,client_id from reading_data ");
sql.append(" where region_code is not null and grade_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY region_code,grade_code,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookComp(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select (case book_type_code when 'DIGITAL' then 1 else 2 end ) book_type,left(`timestamp`,4) year,SUBSTR(`timestamp`,6,2) mon,count(*)/count(distinct user_id) cc,client_id from reading_data ");
sql.append(" where book_type_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY book_type_code,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRcostTrend(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select left(`timestamp`,4) year,count(DISTINCT user_id) cc,client_id from reading_data ");
sql.append(" where user_id is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY left(`timestamp`,4) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRcostSex(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select grade_code,age,(case sex_code when '1' then '男' else '女' end ) sex_name,left(`timestamp`,7) date6,count(*) cc,client_id from reading_data ");
sql.append(" where grade_code >=1 and grade_code <=12 and age is not null and sex_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY grade_code,age,sex_code,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRbookHot(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select grade_code,grade_name,sex_code,(case sex_code when '1' then '男' else '女' end ) sex_name,book_id,book_name,author,pub_name,left(`timestamp`,4) year,count(*) cc,client_id from reading_data ");
sql.append(" where book_id is not null and grade_code is not null and sex_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY grade_code,sex_code,book_id,left(`timestamp`,4) having count(*)>=5");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulZtreg(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select region_code,region_name,left(clc_code,1)clc_code ,left(`timestamp`,7) date6,count(*) cc,client_id from reading_data ");
sql.append(" where clc_code is not null and region_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY region_code,left(clc_code,1),left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulZtsex(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select region_code,region_name,sex_code,(case sex_code when '1' then '男' else '女' end ) sex_name,left(clc_code,1)clc_code ,left(`timestamp`,7) date6,count(*) cc,client_id from reading_data ");
sql.append(" where clc_code is not null and region_code is not null and sex_code is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY region_code, sex_code,left(clc_code,1),left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulZtage(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select region_code,age,left(clc_code,1) clc_code ,left(`timestamp`,7) date6,count(*) cc,client_id from reading_data ");
sql.append(" where clc_code is not null and region_code is not null and age is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY region_code, age,left(clc_code,1),left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRreadQuantity(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select user_id,region_code,left(`timestamp`,7) date6,SUBSTR(`timestamp`,6,2) mon,count(*) cc from reading_data ");
sql.append(" where user_id is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY user_id,left(`timestamp`,7) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
public List<LinkedHashMap> queryRmulAuth(Date beginTime, Date endTime){
Map<String, Object> params = new HashMap<>();
AlphaSql alphaSql = AlphaSqlFactory.instance().getDefaultAlphaSql();
StringBuffer sql = new StringBuffer();
sql.append("select sex_code,(case sex_code when '1' then '男' else '女' end ) sex_name ,grade_code,grade_name,author_id,author,left(`timestamp`,4) year,count(*) cc,client_id from reading_data ");
sql.append(" where sex_code is not null and grade_code is not null and author is not null and verb_name<>'归还' ");
sql.append(" and create_time >=:beginTime and create_time <:endTime ");
params.put("beginTime", beginTime);
params.put("endTime", endTime);
sql.append(" GROUP BY sex_code,grade_code, author,left(`timestamp`,4) ");
AlphaSqlBuilder alphaSqlBuilder = alphaSql.with(sql.toString(), null);
alphaSqlBuilder.useParams(params);
List<LinkedHashMap> searchCount = alphaSqlBuilder.queryAll(LinkedHashMap.class);
return searchCount;
}
}
package com.chineseall.djgdata.dao;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mongo.dao.StaticCacheDimensionDocumentMongoDao;
import com.chineseall.djgdata.model.ReadingData;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Component
public class ReadingDataDao extends StaticCacheDimensionDocumentMongoDao<ReadingData, String> {
public List<ReadingData> queryDataByTime(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("createTime").gte(beginTime).lt(endTime);
return query(new Query(criteria));
}
public ReadingData queryDataByTimeFirst(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("createTime").gte(beginTime).lt(endTime);
return query(new Query(criteria).with(new Sort(Sort.Direction.ASC, "createTime")).limit(1)).stream().findFirst().orElse(null);
}
public ReadingData queryDataByTimeLast(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("createTime").gte(beginTime).lt(endTime);
return query(new Query(criteria).with(new Sort(Sort.Direction.DESC, "createTime")).limit(1)).stream().findFirst().orElse(null);
}
public Long countByTime(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("createTime").gte(beginTime).lt(endTime);
return count(new Query(criteria));
}
public List<ReadingData> queryDataByTimestamp(Date beginTime, Date endTime){
Criteria criteria = Criteria.where("timestamp").gte(beginTime).lt(endTime);
return query(new Query(criteria));
}
public List<ReadingData> queryDatas(Long begin, Long end){
return query(new Query(Criteria.where("_id").gte(begin).lt(end)));
}
}
package com.chineseall.djgdata.dao;
import cn.sh.chineseall.framework.core.repackaged.org.springframework.data.domain.Sort;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.ShangtuData;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.List;
@Component
public class ShangtuDataDao extends AlphaStaticJdbcDao<ShangtuData, Long> {
@Override
protected void calculateCacheDimensions(ShangtuData shangtuData, Collection<String> collection) {
}
public List<ShangtuData> queryDatas(Integer begin, Integer end){
return query(new Query(Criteria.where("id").gte(begin).lt(end)).with(new Sort(Sort.Direction.ASC, "id")));
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RauthorCount;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RauthCountDao extends AlphaStaticJdbcDao<RauthorCount, Long> {
@Override
protected void calculateCacheDimensions(RauthorCount rauthorCount, Collection<String> collection) {
}
public RauthorCount queryByParams(Long userId, String date6, String author){
Criteria criteria = Criteria.where("user_id").is(userId).and("date6").is(date6).and("author").is(author);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookBooks;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookBooksDao extends AlphaStaticJdbcDao<RbookBooks, Long> {
@Override
protected void calculateCacheDimensions(RbookBooks rbookBooks, Collection<String> collection) {
}
public RbookBooks queryByParams(Long schoolCode, String date6){
Criteria criteria = Criteria.where("school_id").is(schoolCode).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookComp;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookCompDao extends AlphaStaticJdbcDao<RbookComp, Long> {
@Override
protected void calculateCacheDimensions(RbookComp rbookComp, Collection<String> collection) {
}
public RbookComp queryByParams(String bookType, String year, Long mon){
Criteria criteria = Criteria.where("book_type").is(bookType).and("year").is(year).and("month").is(mon);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookHot;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookHotDao extends AlphaStaticJdbcDao<RbookHot, Long> {
@Override
protected void calculateCacheDimensions(RbookHot rbookHot, Collection<String> collection) {
}
public RbookHot queryByParams(Long gradeId, Long sexId, Long bookId, String date6){
Criteria criteria = Criteria.where("grade_id").is(gradeId).and("sex_id").is(sexId).and("book_id").is(bookId).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookMtrend;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookMtrendDao extends AlphaStaticJdbcDao<RbookMtrend, Long> {
@Override
protected void calculateCacheDimensions(RbookMtrend rbookMtrend, Collection<String> collection) {
}
public RbookMtrend queryByParams(Long regionId, Long gradeId, String year, Long mon){
Criteria criteria = Criteria.where("region_id").is(regionId).and("grade_id").is(gradeId).and("year").is(year).and("month").is(mon);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookRate;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookRateDao extends AlphaStaticJdbcDao<RbookRate, Long> {
@Override
protected void calculateCacheDimensions(RbookRate rbookRate, Collection<String> collection) {
}
public RbookRate queryByParams(String ztId, String year){
Criteria criteria = Criteria.where("zt_id").is(ztId).and("year").is(year);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookStar;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookStarDao extends AlphaStaticJdbcDao<RbookStar, Long> {
@Override
protected void calculateCacheDimensions(RbookStar rbookStar, Collection<String> collection) {
}
public RbookStar queryByParams(Long userId, String date6){
Criteria criteria = Criteria.where("student_id").is(userId).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RbookYtrend;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RbookYtrendDao extends AlphaStaticJdbcDao<RbookYtrend, Long> {
@Override
protected void calculateCacheDimensions(RbookYtrend rbookYtrend, Collection<String> collection) {
}
public RbookYtrend queryByParams(Long regionId, String year){
Criteria criteria = Criteria.where("region_id").is(regionId).and("year").is(year);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RcostSex;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RcostSexDao extends AlphaStaticJdbcDao<RcostSex, Long> {
@Override
protected void calculateCacheDimensions(RcostSex rcostSex, Collection<String> collection) {
}
public RcostSex queryByParams(String grade,Long ageId, String sex, String date6){
Criteria criteria = Criteria.where("grade").is(grade).and("age_id").is(ageId).and("sex").is(sex).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RcostTrend;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RcostTrendDao extends AlphaStaticJdbcDao<RcostTrend, Long> {
@Override
protected void calculateCacheDimensions(RcostTrend rcostTrend, Collection<String> collection) {
}
public RcostTrend queryByParams(String year){
Criteria criteria = Criteria.where("year").is(year);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulAuth;
import com.chineseall.djgdata.model.djg.RmulZtage;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulAuthDao extends AlphaStaticJdbcDao<RmulAuth, Long> {
@Override
protected void calculateCacheDimensions(RmulAuth rmulAuth, Collection<String> collection) {
}
public RmulAuth queryByParams(Long sexCode,Long gradeCode, String author, String year){
Criteria criteria = Criteria.where("sex_id").is(sexCode).and("grade_id").is(gradeCode).and("author_name").is(author).and("date6").is(year);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulPub;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulPubDao extends AlphaStaticJdbcDao<RmulPub, Long> {
@Override
protected void calculateCacheDimensions(RmulPub rmulPub, Collection<String> collection) {
}
public RmulPub queryByParams(Long pubCode, String date6){
Criteria criteria = Criteria.where("pub_id").is(pubCode).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulPubtrend;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulPubtrendDao extends AlphaStaticJdbcDao<RmulPubtrend, Long> {
@Override
protected void calculateCacheDimensions(RmulPubtrend rmulPubtrend, Collection<String> collection) {
}
public RmulPubtrend queryByParams(Long pubId, String year, Long mon){
Criteria criteria = Criteria.where("pub_id").is(pubId).and("year").is(year).and("month").is(mon);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulZtage;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulZtageDao extends AlphaStaticJdbcDao<RmulZtage, Long> {
@Override
protected void calculateCacheDimensions(RmulZtage rmulZtage, Collection<String> collection) {
}
public RmulZtage queryByParams(Long regionId,Long ageId, String ztId, String date6){
Criteria criteria = Criteria.where("region_id").is(regionId).and("age_id").is(ageId).and("zt_id").is(ztId).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulZtreg;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulZtregDao extends AlphaStaticJdbcDao<RmulZtreg, Long> {
@Override
protected void calculateCacheDimensions(RmulZtreg rmulZtreg, Collection<String> collection) {
}
public RmulZtreg queryByParams(Long regionId, String ztId, String date6){
Criteria criteria = Criteria.where("region_id").is(regionId).and("zt_id").is(ztId).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulZtsex;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulZtsexDao extends AlphaStaticJdbcDao<RmulZtsex, Long> {
@Override
protected void calculateCacheDimensions(RmulZtsex rmulZtsex, Collection<String> collection) {
}
public RmulZtsex queryByParams(Long regionId,Long sexId, String ztId, String date6){
Criteria criteria = Criteria.where("region_id").is(regionId).and("sex_id").is(sexId).and("zt_id").is(ztId).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RmulZttrend;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RmulZttrendDao extends AlphaStaticJdbcDao<RmulZttrend, Long> {
@Override
protected void calculateCacheDimensions(RmulZttrend rmulZttrend, Collection<String> collection) {
}
public RmulZttrend queryByParams(String ztId, String year, Long mon){
Criteria criteria = Criteria.where("zt_id").is(ztId).and("year").is(year).and("month").is(mon);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RpublishingCount;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RpublishingCountDao extends AlphaStaticJdbcDao<RpublishingCount, Long> {
@Override
protected void calculateCacheDimensions(RpublishingCount rpublishingCount, Collection<String> collection) {
}
public RpublishingCount queryByParams(Long userId, String date6, String pubName){
Criteria criteria = Criteria.where("user_id").is(userId).and("date6").is(date6).and("publishing").is(pubName);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RreadComp;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RreadCompDao extends AlphaStaticJdbcDao<RreadComp, Long> {
@Override
protected void calculateCacheDimensions(RreadComp rreadComp, Collection<String> collection) {
}
public RreadComp queryByParams(Long userId, String date6, String bookType){
Criteria criteria = Criteria.where("user_id").is(userId).and("date6").is(date6).and("type").is(bookType);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RauthorCount;
import com.chineseall.djgdata.model.djg.RreadQuantity;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RreadQuantityDao extends AlphaStaticJdbcDao<RreadQuantity, Long> {
@Override
protected void calculateCacheDimensions(RreadQuantity rreadQuantity, Collection<String> collection) {
}
public RreadQuantity queryByParams(Long userId, String date6){
Criteria criteria = Criteria.where("user_id").is(userId).and("date6").is(date6);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.dao.djg;
import cn.sh.chineseall.framework.dao.core.hql.Criteria;
import cn.sh.chineseall.framework.dao.core.hql.Query;
import cn.sh.chineseall.framework.dao.mysql.jdbc.dao.AlphaStaticJdbcDao;
import com.chineseall.djgdata.model.djg.RtypeCount;
import org.springframework.stereotype.Component;
import java.util.Collection;
@Component
public class RtypeCountDao extends AlphaStaticJdbcDao<RtypeCount, Long> {
@Override
protected void calculateCacheDimensions(RtypeCount rtypeCount, Collection<String> collection) {
}
public RtypeCount queryByParams(Long userId, String date6, String clcCode){
Criteria criteria = Criteria.where("user_id").is(userId).and("date6").is(date6).and("type").is(clcCode);
return query(new Query(criteria)).stream().findFirst().orElse(null);
}
}
package com.chineseall.djgdata.model;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "job_record")
public class JobRecord implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
@DocumentField
private Long id;
@DocumentField("job_name")
private String jobName;
@DocumentField("create_time")
private Date createTime;
@DocumentField("process_end_time")
private Date processEndTime;
@DocumentField("begin_time")
private Date beginTime;
@DocumentField("end_time")
private Date endTime;
@DocumentField("success")
private Boolean success;
@DocumentField("suc_count")
private Long sucCount;
@DocumentField("fail_count")
private Long failCount;
@DocumentField("data_count")
private Long dataCount;
}
package com.chineseall.djgdata.model;
import cn.sh.chineseall.framework.dao.core.CacheDimensionDocument;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.util.Date;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "reading_data")
public class ReadingBaseInfo implements CacheDimensionDocument {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField("uuid")
private String uuid;
@DocumentField("user_id")
private String userId;
@DocumentField("real_name")
private String realName;
@DocumentField
private String birthday;
@DocumentField
private String race;
@DocumentField("student_code")
private String studentCode;
@DocumentField
private String age;
@DocumentField("sex_code")
private String sexCode;
@DocumentField("sex_name")
private String sexName;
@DocumentField("grade_code")
private String gradeCode;
@DocumentField("grade_name")
private String gradeName;
@DocumentField("stage_code")
private String stageCode;
@DocumentField("stage_name")
private String stageName;
@DocumentField("school_id")
private String schoolId;
@DocumentField("school_code")
private String schoolCode;
@DocumentField("school_name")
private String schoolName;
@DocumentField("school_addr")
private String schoolAddr;
@DocumentField("region_code")
private String regionCode;
@DocumentField("region_name")
private String regionName;
@DocumentField("verb_type")
private String verbType;
@DocumentField("verb_name")
private String verbName;
@DocumentField("lend_type_name")
private String lendTypeName;
@DocumentField("lend_type_code")
private String lendTypeCode;
@DocumentField("lend_date")
private String lendDate;
@DocumentField("lend_expired_date")
private String lendExpiredDate;
@DocumentField("lend_addr")
private String lendAddr;
@DocumentField("book_id")
private String bookId;
@DocumentField("book_type_code")
private String bookTypeCode;
@DocumentField("book_type_name")
private String bookTypeName;
@DocumentField("bar_code")
private String barCode;
@DocumentField("book_name")
private String bookName;
@DocumentField("isbn")
private String isbn;
@DocumentField("pub_date")
private String pubDate;
@DocumentField("clc_code")
private String clcCode;
@DocumentField("words_count")
private String wordsCount;
@DocumentField("page_count")
private String pageCount;
@DocumentField
private String price;
@DocumentField
private String author;
@DocumentField("author_id")
private String authorId;
@DocumentField("pub_name")
private String pubName;
@DocumentField("pub_code")
private String pubCode;
@DocumentField("subject_code")
private String subjectCode;
@DocumentField("subject_name")
private String subjectName;
@DocumentField("client_id")
private String clientId;
@DocumentField("client_name")
private String clientName;
@DocumentField("create_time")
private Date createTime;
@DocumentField
private Date timestamp;
@Override
public String[] generateCacheDimensions() {
return new String[0];
}
}
package com.chineseall.djgdata.model;
import cn.sh.chineseall.framework.dao.core.CacheDimensionDocument;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentCreateTimestamp;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentCollection;
import cn.sh.chineseall.framework.dao.core.annotation.mongo.DocumentDatabase;
import lombok.Data;
import java.util.Date;
import java.util.Map;
@Data
@DocumentConnection(configName = "mongo")
@DocumentDatabase(database = "xapi")
@DocumentCollection(collection = "reading_data")
public class ReadingData implements CacheDimensionDocument {
@DocumentId
private String id;
@DocumentCreateTimestamp
private Date createTime;
@DocumentField
private Date timestamp;
@DocumentField
private Map<String, Object> actor;
@DocumentField
private Map<String, Object> verb;
@DocumentField
private Map<String, Object> object;
@DocumentField
private Boolean valid;
@DocumentField
private String clientId;
@DocumentField
private String clientName;
@Override
public String[] generateCacheDimensions() {
return new String[0];
}
public ReadingBaseInfo toReadingBaseInfo(){
ReadingBaseInfo readingBaseInfo = new ReadingBaseInfo();
readingBaseInfo.setUuid(this.id);
readingBaseInfo.setCreateTime(this.createTime);
readingBaseInfo.setTimestamp(this.timestamp);
readingBaseInfo.setClientId(this.clientId);
readingBaseInfo.setClientName(this.clientName);
if(this.actor.get("userInfo")!=null){
Map<String, Object> userInfo = (Map<String, Object>) this.actor.get("userInfo");
readingBaseInfo.setUserId(toString(userInfo.get("userId")));
readingBaseInfo.setRealName(toString(userInfo.get("realName")));
readingBaseInfo.setBirthday(toString(userInfo.get("birthday")));
readingBaseInfo.setRace(toString(userInfo.get("race")));
readingBaseInfo.setStudentCode(toString(userInfo.get("studentCode")));
readingBaseInfo.setAge(toString(userInfo.get("age")));
if(userInfo.get("sex")!=null){
Map<String, Object> sex = (Map<String, Object>) userInfo.get("sex");
readingBaseInfo.setSexCode(toString(sex.get("sexCode")));
readingBaseInfo.setSexName(toString(sex.get("sexName")));
}
if(userInfo.get("grade")!=null){
Map<String, Object> grade = (Map<String, Object>) userInfo.get("grade");
readingBaseInfo.setGradeCode(toString(grade.get("gradeCode")));
readingBaseInfo.setGradeName(toString(grade.get("gradeName")));
}
if(userInfo.get("stage")!=null){
Map<String, Object> stage = (Map<String, Object>) userInfo.get("stage");
readingBaseInfo.setStageCode(toString(stage.get("stageCode")));
readingBaseInfo.setStageName(toString(stage.get("stageName")));
}
if(userInfo.get("schoolInfo")!=null){
Map<String, Object> schoolInfo = (Map<String, Object>) userInfo.get("schoolInfo");
readingBaseInfo.setSchoolId(toString(schoolInfo.get("schoolId")));
readingBaseInfo.setSchoolCode(toString(schoolInfo.get("schoolCode")));
readingBaseInfo.setSchoolName(toString(schoolInfo.get("schoolName")));
readingBaseInfo.setSchoolAddr(toString(schoolInfo.get("schoolAddr")));
}
if(userInfo.get("regionInfo")!=null){
Map<String, Object> regionInfo = (Map<String, Object>) userInfo.get("regionInfo");
readingBaseInfo.setRegionCode(toString(regionInfo.get("regionCode")));
readingBaseInfo.setRegionName(toString(regionInfo.get("regionName")));
}
}
readingBaseInfo.setVerbType(toString(this.verb.get("verbType")));
readingBaseInfo.setVerbName(toString(this.verb.get("verbName")));
if(this.object.get("lendInfo")!=null){
Map<String, Object> lendInfo = (Map<String, Object>) this.object.get("lendInfo");
if(lendInfo.get("lendType")!=null){
Map<String, Object> lendType = (Map<String, Object>) lendInfo.get("lendType");
readingBaseInfo.setLendTypeCode(toString(lendType.get("typeCode")));
readingBaseInfo.setLendTypeName(toString(lendType.get("typeName")));
}
readingBaseInfo.setLendDate(toString(lendInfo.get("lendDate")));
readingBaseInfo.setLendExpiredDate(toString(lendInfo.get("lendExpiredDate")));
readingBaseInfo.setLendAddr(toString(lendInfo.get("lendAddr")));
}
if(this.object.get("bookInfo")!=null){
Map<String, Object> bookInfo = (Map<String, Object>) this.object.get("bookInfo");
if(bookInfo.get("bookType")!=null){
Map<String, Object> bookType = (Map<String, Object>) bookInfo.get("bookType");
readingBaseInfo.setBookTypeCode(toString(bookType.get("typeCode")));
readingBaseInfo.setBookTypeName(toString(bookType.get("typeName")));
}
readingBaseInfo.setBookId(toString(bookInfo.get("bookId")));
readingBaseInfo.setBarCode(toString(bookInfo.get("barCode")));
readingBaseInfo.setBookName(toString(bookInfo.get("bookName")));
readingBaseInfo.setIsbn(toString(bookInfo.get("isbn")));
readingBaseInfo.setPubDate(toString(bookInfo.get("pubDate")));
readingBaseInfo.setClcCode(toString(bookInfo.get("clcCode")));
readingBaseInfo.setWordsCount(toString(bookInfo.get("wordsCount")));
readingBaseInfo.setPageCount(toString(bookInfo.get("pageCount")));
readingBaseInfo.setPrice(toString(bookInfo.get("price")));
readingBaseInfo.setAuthorId(toString(bookInfo.get("authorId")));
readingBaseInfo.setAuthor(toString(bookInfo.get("author")));
if(bookInfo.get("pubInfo")!=null){
Map<String, Object> pubInfo = (Map<String, Object>) bookInfo.get("pubInfo");
readingBaseInfo.setPubCode(toString(pubInfo.get("pubCode")));
readingBaseInfo.setPubName(toString(pubInfo.get("pubName")));
}
if(bookInfo.get("subject")!=null){
Map<String, Object> subject = (Map<String, Object>) bookInfo.get("subject");
readingBaseInfo.setSubjectCode(toString(subject.get("subjectCode")));
readingBaseInfo.setSubjectName(toString(subject.get("subjectName")));
}
}
return readingBaseInfo;
}
private String toString(Object ob){
return ob==null?null:ob.toString();
}
}
package com.chineseall.djgdata.model;
import cn.sh.chineseall.framework.dao.core.CacheDimensionDocument;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import com.chineseall.djgdata.common.enums.BookType;
import lombok.Data;
import java.util.HashMap;
import java.util.Map;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "st")
public class ShangtuData implements CacheDimensionDocument {
@DocumentId
private Long id;
@DocumentField
private String jhlx;//借还状态
@DocumentField
private String jhrq;//借还日期
@DocumentField
private String yhrq;//预还日期 只有外借才有值
@DocumentField
private String jhdd;//借还地点
@DocumentField
private String tstm;//图书条码
@DocumentField
private String sm ;//书名
@DocumentField
private String isbn;//isbn号
@DocumentField
private String zz ;//作者
@DocumentField
private String cbs ;//出版社
@DocumentField
private String cbrq;//出版日期
@DocumentField
private String flh ;//分类号 中图分类号
@DocumentField
private String ys ;//页数
@DocumentField
private String dj ;//定价
@DocumentField
private String xjh ;//学籍号
@DocumentField
private String xxdm;//学校代码
@DocumentField
private String xxmc;//学校名称
@DocumentField
private String zjlx;//
@DocumentField
private String xbm ;//性别
@DocumentField
private String csrq;//出生日期
@DocumentField
private String mz ;//民族
@DocumentField
private String gj ;//国籍
@DocumentField
private String xd ;//学段 1、小学,2、中学
@DocumentField
private String xm ;//姓名
@DocumentField
private String sfz ;//身份证
@DocumentField
private String qxdm;//区县代码
@DocumentField
private String student_id ;//学生ID
@DocumentField
private String school_id ;//学校ID
@DocumentField
private String area_id;//区县ID
@DocumentField
private String book_id;//图书ID
@DocumentField
private String auth_id;//作者ID
@DocumentField
private String pub_id ;//出版社ID
@DocumentField
private String date6_birth;//出生日期
@DocumentField
private String date6_enter ;//入学时间
@DocumentField
private String date6_lend ;//借还时间
@DocumentField
private String grade_id ;//年级ID
@DocumentField
private String age_id ;//年龄ID
@DocumentField
private String period_id ;//学段ID
@DocumentField
private String sex_id ;//性别ID
@DocumentField
private String zt_id;//性别ID
@Override
public String[] generateCacheDimensions() {
return new String[0];
}
public ReadingData toReadingData(){
ReadingData readingData = new ReadingData();
Map<String, Object> actor = new HashMap<>();
Map<String, Object> userInfo = new HashMap<>();
userInfo.put("userId", this.student_id);
userInfo.put("realName", this.xm);
userInfo.put("birthday", this.csrq);
userInfo.put("race", this.mz);
userInfo.put("studentCode", this.xjh);
userInfo.put("age", this.age_id);
Map<String, Object> sex = new HashMap<>();
sex.put("sexCode", this.xbm);
sex.put("sexName", null);
userInfo.put("sex", sex);
Map<String, Object> grade = new HashMap<>();
grade.put("gradeCode", this.grade_id);
grade.put("gradeName", null);
userInfo.put("grade", grade);
Map<String, Object> stage = new HashMap<>();
stage.put("stageCode", this.xd);
stage.put("stageName", null);
userInfo.put("stage", stage);
Map<String, Object> schoolInfo = new HashMap<>();
schoolInfo.put("schoolId", this.school_id);
schoolInfo.put("schoolCode", this.xxdm);
schoolInfo.put("schoolName", this.xxmc);
schoolInfo.put("schoolAddr", null);
userInfo.put("schoolInfo", schoolInfo);
Map<String, Object> regionInfo = new HashMap<>();
regionInfo.put("regionCode", this.qxdm);
regionInfo.put("regionName", null);
userInfo.put("regionInfo", regionInfo);
actor.put("userInfo", userInfo);
readingData.setActor(actor);
Map<String, Object> verb = new HashMap<>();
verb.put("verbType", null);
verb.put("verbName", this.jhlx);
readingData.setVerb(verb);
Map<String, Object> object = new HashMap<>();
Map<String, Object> lendInfo = new HashMap<>();
Map<String, Object> lendType = new HashMap<>();
lendType.put("typeCode", null);
lendType.put("typeName", this.jhlx);
lendInfo.put("lendType", lendType);
lendInfo.put("lendDate", this.jhrq);
lendInfo.put("lendExpiredDate", this.yhrq);
lendInfo.put("lendAddr", this.jhdd);
object.put("lendInfo", lendInfo);
Map<String, Object> bookInfo = new HashMap<>();
Map<String, Object> bookType = new HashMap<>();
bookType.put("typeCode", BookType.PAPER.getCode());
bookType.put("typeName", BookType.PAPER.getDesc());
bookInfo.put("bookType", bookType);
bookInfo.put("bookId", this.book_id);
bookInfo.put("barCode", this.tstm);
bookInfo.put("bookName", this.sm);
bookInfo.put("isbn", this.isbn);
bookInfo.put("pubDate", this.cbrq);
bookInfo.put("clcCode", this.flh);
bookInfo.put("wordsCount", null);
bookInfo.put("pageCount", this.ys);
bookInfo.put("price", this.dj);
bookInfo.put("author", this.zz);
Map<String, Object> pubInfo = new HashMap<>();
pubInfo.put("pubCode", this.pub_id);
pubInfo.put("pubName", this.cbs);
bookInfo.put("pubInfo", pubInfo);
Map<String, Object> subject = new HashMap<>();
subject.put("subjectCode", null);
subject.put("subjectName", null);
bookInfo.put("subject", subject);
object.put("bookInfo", bookInfo);
readingData.setObject(object);
return readingData;
}
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_author_count")
public class RauthorCount implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long region_id;
@DocumentField
private Long user_id;
@DocumentField
private String date6;
@DocumentField
private Long month;
@DocumentField
private String author;
@DocumentField
private Long cc;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_books")
public class RbookBooks implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private Long school_id;
@DocumentField
private String school_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_comp")
public class RbookComp implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String book_type;
@DocumentField
private String year;
@DocumentField
private Long month;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_hot")
public class RbookHot implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long grade_id;
@DocumentField
private String grade_name;
@DocumentField
private Long sex_id;
@DocumentField
private String sex_name;
@DocumentField
private Long book_id;
@DocumentField
private String book_name;
@DocumentField
private String author;
@DocumentField
private String press;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_mtrend")
public class RbookMtrend implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private Long grade_id;
@DocumentField
private String grade_name;
@DocumentField
private String year;
@DocumentField
private Long month;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_rate")
public class RbookRate implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String zt_id;
@DocumentField
private String zt_name;
@DocumentField
private String year;
@DocumentField
private Long used_count;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_star")
public class RbookStar implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private Long student_id;
@DocumentField
private String student_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_book_ytrend")
public class RbookYtrend implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private String year;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_cost_sex")
public class RcostSex implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String grade;
@DocumentField
private Long age_id;
@DocumentField
private String age_name;
@DocumentField
private String sex;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_cost_trend")
public class RcostTrend implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String year;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_auth")
public class RmulAuth implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long sex_id;
@DocumentField
private String sex_name;
@DocumentField
private Long grade_id;
@DocumentField
private String grade_name;
@DocumentField
private Long author_id;
@DocumentField
private String author_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_pub")
public class RmulPub implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long pub_id;
@DocumentField
private String pub_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_pubtrend")
public class RmulPubtrend implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long pub_id;
@DocumentField
private String pub_name;
@DocumentField
private String year;
@DocumentField
private Long month;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_ztage")
public class RmulZtage implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String zt_id;
@DocumentField
private String zt_name;
@DocumentField
private Long age_id;
@DocumentField
private String age_name;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_ztreg")
public class RmulZtreg implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String zt_id;
@DocumentField
private String zt_name;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_ztsex")
public class RmulZtsex implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String zt_id;
@DocumentField
private String zt_name;
@DocumentField
private Long sex_id;
@DocumentField
private String sex_name;
@DocumentField
private Long region_id;
@DocumentField
private String region_name;
@DocumentField
private String date6;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_mul_zttrend")
public class RmulZttrend implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String zt_id;
@DocumentField
private String zt_name;
@DocumentField
private String year;
@DocumentField
private Long month;
@DocumentField
private Long cc;
@DocumentField
private Integer level_type;
@DocumentField
private Long level_id;
@DocumentField
private Integer src_type;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_publishing_count")
public class RpublishingCount implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String publishing;
@DocumentField
private Long user_id;
@DocumentField
private String date6;
@DocumentField
private Long month;
@DocumentField
private Long cc;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_read_comp")
public class RreadComp implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String type;
@DocumentField
private Long user_id;
@DocumentField
private String user_name;
@DocumentField
private String date6;
@DocumentField
private Long month;
@DocumentField
private Long cc;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_read_quantity")
public class RreadQuantity implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private Long region_id;
@DocumentField
private Long user_id;
@DocumentField
private String date6;
@DocumentField
private Long month;
@DocumentField
private Long coll_count;
@DocumentField
private Long read_count;
@DocumentField
private Long not_read;
@DocumentField
private Long read_duration;
@DocumentField
private Long words_count;
@DocumentField
private Long pages_count;
}
package com.chineseall.djgdata.model.djg;
import cn.sh.chineseall.framework.dao.core.DocumentIdAutoGenerator;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentConnection;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentField;
import cn.sh.chineseall.framework.dao.core.annotation.DocumentId;
import cn.sh.chineseall.framework.dao.core.annotation.mysql.DocumentTable;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@DocumentConnection(configName = "main")
@DocumentTable(table = "r_type_count")
public class RtypeCount implements Serializable {
@DocumentId(autoGenerator = DocumentIdAutoGenerator.AUTO_INC)
private Long id;
@DocumentField
private String type;
@DocumentField
private Long user_id;
@DocumentField
private Long region_id;
@DocumentField
private String date6;
@DocumentField
private Long month;
@DocumentField
private Long cc;
}
package com.chineseall.djgdata.service;
import com.chineseall.djgdata.common.vo.TechMessage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Date;
public interface DataService {
@RequestMapping(value = "/init/shangtu", method = {RequestMethod.GET})
TechMessage initShangtuData();
@RequestMapping(value = "/init/dianjiaoguan", method = {RequestMethod.GET})
TechMessage initDianjiaoguan();
@RequestMapping(value = "/process/dianjiaoguan", method = {RequestMethod.GET})
TechMessage processDianjiaoguan(@RequestParam(value = "begin_time", required = false) Date beginTime, @RequestParam(value = "end_time", required = false)Date endTime);
@RequestMapping(value = "/process/readingdata", method = {RequestMethod.GET})
TechMessage processReadingData(@RequestParam(value = "begin_time", required = false) Date beginTime, @RequestParam(value = "end_time", required = false)Date endTime);
}
package com.chineseall.djgdata.service;
import com.chineseall.djgdata.model.ReadingData;
public interface ReadingDataService {
ReadingData getById(String id);
void save(ReadingData readingData);
}
package com.chineseall.djgdata.service.impl;
import cn.sh.chineseall.framework.core.util.StringUtils;
import cn.sh.chineseall.framework.lang.calendar.DateUtils;
import com.alibaba.fastjson.JSONObject;
import com.chineseall.djgdata.common.enums.ResultEnum;
import com.chineseall.djgdata.common.utils.DateUtil;
import com.chineseall.djgdata.common.vo.TechMessage;
import com.chineseall.djgdata.dao.JobRecordDao;
import com.chineseall.djgdata.dao.ReadingBaseInfoDao;
import com.chineseall.djgdata.dao.ReadingDataDao;
import com.chineseall.djgdata.dao.ShangtuDataDao;
import com.chineseall.djgdata.dao.djg.*;
import com.chineseall.djgdata.model.JobRecord;
import com.chineseall.djgdata.model.ReadingBaseInfo;
import com.chineseall.djgdata.model.ReadingData;
import com.chineseall.djgdata.model.ShangtuData;
import com.chineseall.djgdata.model.djg.*;
import com.chineseall.djgdata.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@RestController
public class DataServiceImpl implements DataService {
@Autowired
private ReadingDataDao readingDataDao;
@Autowired
private ReadingBaseInfoDao readingBaseInfoDao;
@Autowired
private ShangtuDataDao shangtuDataDao;
@Autowired
private JobRecordDao jobRecordDao;
@Autowired
private RauthCountDao rauthCountDao;
@Autowired
private RreadCompDao rreadCompDao;
@Autowired
private RpublishingCountDao rpublishingCountDao;
@Autowired
private RtypeCountDao rtypeCountDao;
@Autowired
private RbookRateDao rbookRateDao;
@Autowired
private RmulZttrendDao rmulZttrendDao;
@Autowired
private RmulPubDao rmulPubDao;
@Autowired
private RmulPubtrendDao rmulPubtrendDao;
@Autowired
private RbookStarDao rbookStarDao;
@Autowired
private RbookBooksDao rbookBooksDao;
@Autowired
private RbookYtrendDao rbookYtrendDao;
@Autowired
private RbookMtrendDao rbookMtrendDao;
@Autowired
private RbookCompDao rbookCompDao;
@Autowired
private RcostTrendDao rcostTrendDao;
@Autowired
private RcostSexDao rcostSexDao;
@Autowired
private RbookHotDao rbookHotDao;
@Autowired
private RmulZtregDao rmulZtregDao;
@Autowired
private RmulZtsexDao rmulZtsexDao;
@Autowired
private RmulZtageDao rmulZtageDao;
@Autowired
private RmulAuthDao rmulAuthDao;
@Autowired
private RreadQuantityDao rreadQuantityDao;
private static final Map<String, Object> clcType = (Map<String,Object>) JSONObject.parseObject("{\"A\":\"马列毛邓\",\"B\":\"哲学、宗教\",\"C\":\"社会科学总论\",\"D\":\"政治、法律\",\"E\":\"军事\",\"F\":\"经济\",\"G\":\"文化、科学、教育、体育\",\"H\":\"语言、文字\",\"I\":\"文学\",\"J\":\"艺术\",\"K\":\"历史、地理\",\"N\":\"自然科学总论\",\"O\":\"数理科学和化学\",\"P\":\"天文学、地球科学\",\"Q\":\"生物科学\",\"R\":\"医药、卫生\",\"S\":\"农业科学\",\"T\":\"工业技术\",\"U\":\"交通运输\",\"V\":\"航空、航天\",\"X\":\"环境科学、安全科学\",\"Z\":\"综合性图书\"}");
private static final Map<String, Object> gradeType = (Map<String,Object>) JSONObject.parseObject("{\"1\":\"一年级\",\"2\":\"二年级\",\"3\":\"三年级\",\"4\":\"四年级\",\"5\":\"五年级\",\"6\":\"六年级\",\"7\":\"七年级\",\"8\":\"八年级\",\"9\":\"九年级\",\"10\":\"十年级\",\"11\":\"十一年级\",\"12\":\"十二年级\"}");
private static final Map<String, Object> areaType = (Map<String,Object>) JSONObject.parseObject("{\"310101\":\"黄浦区\",\"310104\":\"徐汇区\",\"310105\":\"长宁区\",\"310106\":\"静安区\",\"310107\":\"普陀区\",\"310109\":\"虹口区\",\"310110\":\"杨浦区\",\"310112\":\"闵行区\",\"310113\":\"宝山区\",\"310114\":\"嘉定区\",\"310115\":\"浦东新区\",\"310116\":\"金山区\",\"310117\":\"松江区\",\"310118\":\"青浦区\",\"310120\":\"奉贤区\",\"310151\":\"崇明区\"}");
private static final String shangtuClientId = "shangtuClentId";
private static AtomicBoolean isRunning = new AtomicBoolean(false);
private static AtomicBoolean isRunning2 = new AtomicBoolean(false);
@Override
public TechMessage initShangtuData() {
int count = 10000;
int i = 0;
while(true) {
List<ShangtuData> shangtuDatas = shangtuDataDao.queryDatas(i*count, (i+1)*count);
if (shangtuDatas.size() == 0) {
break;
}
List<ReadingData> readingDatas = new ArrayList<>();
shangtuDatas.forEach(shangtuData -> {
ReadingData readingData = shangtuData.toReadingData();
readingData.setId(shangtuData.getId().toString());
readingData.setCreateTime(new Date());
Date timestamp = DateUtils.stringToDate(shangtuData.getJhrq(), "yyyyMMdd");
readingData.setTimestamp(timestamp);
readingData.setClientId("shangtuClentId");
readingData.setClientName("上图");
readingDataDao.insert(readingData);
});
i++;
}
return new TechMessage(ResultEnum.Success);
}
@Override
public TechMessage initDianjiaoguan() {
int count = 10000;
int n = 0;
while(true) {
List<ReadingData> readingDataList = readingDataDao.queryDatas(n*count*1l, (n+1)*count*1l);
if (readingDataList.size() == 0) {
break;
}
readingDataList.forEach(readingData -> {
ReadingBaseInfo readingBaseInfo = readingData.toReadingBaseInfo();
readingBaseInfo.setCreateTime(new Date());
readingBaseInfoDao.insert(readingBaseInfo);
});
n++;
}
return new TechMessage(ResultEnum.Success);
}
@Scheduled(cron="0 30 0 * * ?")
//@Scheduled(cron="0 0 2 * * ?")
public void processDianjiaoguanJob(){
processDianjiaoguan(DateUtil.getBeginTime(DateUtils.nextDay(new Date(), -1)), DateUtil.getBeginTime(new Date()));
// processDianjiaoguan(DateUtil.getBeginTime(DateUtils.nextDay(new Date(), -1)), new Date());
}
@Override
public TechMessage processDianjiaoguan(@RequestParam(value = "begin_time") Date beginTime, @RequestParam(value = "end_time")Date endTime) {
if (isRunning2.get()){
return new TechMessage(ResultEnum.JobRunning);
}
JobRecord jobRecord = new JobRecord();
jobRecord.setJobName("processDianjiaoguan");
jobRecord.setCreateTime(new Date());
try {
isRunning2.set(true);
Long jobCount1 = jobRecordDao.countRecordByBeginTime("processDianjiaoguan", beginTime);
Long jobCount2 = jobRecordDao.countRecordByEndTime("processDianjiaoguan", endTime);
if(jobCount1 > 0 || jobCount2 > 0){
return new TechMessage(ResultEnum.JobAlreadyRun);
}
System.out.println("..........开始执行跑电教馆大数据基础表"+DateUtils.dateToString(new Date()));
Long count = readingDataDao.countByTime(beginTime, endTime);
jobRecord.setBeginTime(beginTime);
jobRecord.setEndTime(endTime);
jobRecord.setDataCount(count);
if(count>20000l) {
Date bt = readingDataDao.queryDataByTimeFirst(beginTime, endTime).getCreateTime();
//Date bt = DateUtils.stringToDate("2020-09-16 16:10:52", "yyyy-MM-dd hh:mm:ss");;
Date end = addOneMilli(readingDataDao.queryDataByTimeLast(beginTime, endTime).getCreateTime());
while (true) {
Date et = addTwentySec(bt);
boolean endFlag = false;
if (et.after(end)) {
et = end;
endFlag = true;
}
System.out.println("------------1--"+DateUtils.dateToString(new Date()));
List<ReadingData> readingDataList = readingDataDao.queryDataByTime(bt, et);
System.out.println("------------2--"+DateUtils.dateToString(new Date()));
List<ReadingBaseInfo> readingBaseInfos = new ArrayList<>();
readingDataList.forEach(readingData -> {
ReadingBaseInfo readingBaseInfo = readingData.toReadingBaseInfo();
readingBaseInfos.add(readingBaseInfo);
});
readingBaseInfoDao.inserts(readingBaseInfos);
System.out.println("------------3--"+DateUtils.dateToString(new Date()));
bt = et;
if (endFlag) {
break;
}
}
} else {
List<ReadingData> readingDataList = readingDataDao.queryDataByTime(beginTime, endTime);
readingDataList.forEach(readingData -> {
ReadingBaseInfo readingBaseInfo = readingData.toReadingBaseInfo();
readingBaseInfo.setCreateTime(new Date());
readingBaseInfoDao.insert(readingBaseInfo);
});
}
jobRecord.setSuccess(true);
jobRecord.setProcessEndTime(new Date());
jobRecordDao.insert(jobRecord);
System.out.println("..........执行跑电教馆大数据基础表结束"+DateUtils.dateToString(new Date()));
return new TechMessage(ResultEnum.Success);
}catch (Exception e){
e.printStackTrace();
jobRecord.setSuccess(false);
jobRecord.setProcessEndTime(new Date());
jobRecordDao.insert(jobRecord);
}finally {
isRunning2.set(false);
}
return new TechMessage(ResultEnum.Error);
}
@Scheduled(cron="0 30 16 * * ?")
//@Scheduled(cron="0 0 1 * * ?")
public void processReadingDataJob(){
processReadingData(DateUtil.getBeginTime(DateUtils.nextDay(new Date(), -1)), DateUtil.getBeginTime(new Date()));
//processReadingData(DateUtils.stringToDate("2020-09-16 00:00:00"), DateUtils.stringToDate("2020-09-17 00:00:00"));
}
/**
* 跑前一天阅读数据到结果表
* @param beginTime
* @param endTime
* @return
*/
@Override
public TechMessage processReadingData(@RequestParam(value = "begin_time") Date beginTime, @RequestParam(value = "end_time")Date endTime){
if (isRunning.get()){
return new TechMessage(ResultEnum.JobRunning);
}
JobRecord jobRecord = new JobRecord();
jobRecord.setJobName("processReadingDate");
jobRecord.setCreateTime(new Date());
try {
isRunning.set(true);
Long jobCount1 = jobRecordDao.countRecordByBeginTime("processReadingDate", beginTime);
Long jobCount2 = jobRecordDao.countRecordByEndTime("processReadingDate", endTime);
if(jobCount1 > 0 || jobCount2 > 0){
return new TechMessage(ResultEnum.JobAlreadyRun);
}
System.out.println("..........开始执行跑电教馆大数据结果表"+DateUtils.dateToString(new Date()));
Long count = readingBaseInfoDao.countByTime(beginTime, endTime);
jobRecord.setBeginTime(beginTime);
jobRecord.setEndTime(endTime);
jobRecord.setDataCount(count);
System.out.println("processRbookComp---date:"+DateUtils.dateToString(new Date()));
processRbookComp(beginTime, endTime);
System.out.println("processRcostTrend---date:"+DateUtils.dateToString(new Date()));
processRcostTrend(beginTime, endTime);
// 加工数据
if(count>20000l) {
Date bt = readingBaseInfoDao.queryDataByTimeFirst(beginTime, endTime).getCreateTime();
Date end = addOneMilli(readingBaseInfoDao.queryDataByTimeLast(beginTime, endTime).getCreateTime());
int ii = 0;
while (true) {
System.out.println("第:"+ii+"次执行--"+DateUtils.dateToString(bt)+"----------date:"+DateUtils.dateToString(new Date()));
Date et = addOneHundredSec(bt);
boolean endFlag = false;
if (et.after(end)) {
et = end;
endFlag = true;
}
processData(bt, et);
bt = et;
if (endFlag) {
break;
}
ii++;
}
} else {
processData(beginTime, endTime);
}
jobRecord.setSuccess(true);
jobRecord.setProcessEndTime(new Date());
jobRecordDao.insert(jobRecord);
System.out.println("..........执行跑电教馆大数据结果表结束"+DateUtils.dateToString(new Date()));
return new TechMessage(ResultEnum.Success);
}catch (Exception e){
e.printStackTrace();
jobRecord.setSuccess(false);
jobRecord.setProcessEndTime(new Date());
jobRecordDao.insert(jobRecord);
}finally {
isRunning.set(false);
}
return new TechMessage(ResultEnum.Error);
}
public void processData(Date beginTime, Date endTime){
System.out.println("processRauthCount---date:"+DateUtils.dateToString(new Date()));
processRauthCount(beginTime, endTime);
System.out.println("processRreadComp---date:"+DateUtils.dateToString(new Date()));
processRreadComp(beginTime, endTime);
System.out.println("processRpublishingCount---date:"+DateUtils.dateToString(new Date()));
processRpublishingCount(beginTime, endTime);
System.out.println("processRtypeCount---date:"+DateUtils.dateToString(new Date()));
processRtypeCount(beginTime, endTime);
System.out.println("processRbookRate---date:"+DateUtils.dateToString(new Date()));
processRbookRate(beginTime, endTime);
System.out.println("processRmulZttrend---date:"+DateUtils.dateToString(new Date()));
processRmulZttrend(beginTime, endTime);
System.out.println("processRmulPub---date:"+DateUtils.dateToString(new Date()));
processRmulPub(beginTime, endTime);
System.out.println("processRmulPubtrend---date:"+DateUtils.dateToString(new Date()));
processRmulPubtrend(beginTime, endTime);
System.out.println("processRbookStar---date:"+DateUtils.dateToString(new Date()));
processRbookStar(beginTime, endTime);
System.out.println("processRbookBooks---date:"+DateUtils.dateToString(new Date()));
processRbookBooks(beginTime, endTime);
System.out.println("processRbookYtrend---date:"+DateUtils.dateToString(new Date()));
processRbookYtrend(beginTime, endTime);
System.out.println("processRbookMtrend---date:"+DateUtils.dateToString(new Date()));
processRbookMtrend(beginTime, endTime);
System.out.println("processRcostSex---date:"+DateUtils.dateToString(new Date()));
processRcostSex(beginTime, endTime);
System.out.println("processRbookHot---date:"+DateUtils.dateToString(new Date()));
processRbookHot(beginTime, endTime);
System.out.println("processRmulZtreg---date:"+DateUtils.dateToString(new Date()));
processRmulZtreg(beginTime, endTime);
System.out.println("processRmulZtsex---date:"+DateUtils.dateToString(new Date()));
processRmulZtsex(beginTime, endTime);
System.out.println("processRmulZtage---date:"+DateUtils.dateToString(new Date()));
processRmulZtage(beginTime, endTime);
System.out.println("processRmulAuth---date:"+DateUtils.dateToString(new Date()));
processRmulAuth(beginTime, endTime);
System.out.println("processRreadQuantity---date:"+DateUtils.dateToString(new Date()));
processRreadQuantity(beginTime, endTime);
// System.out.println("processRbookHot---date:"+DateUtils.dateToString(new Date()));
// processRbookHot(beginTime, endTime);
// System.out.println("processRmulAuth---date:"+DateUtils.dateToString(new Date()));
// processRmulAuth(beginTime, endTime);
}
public void processRauthCount(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRauthCount(beginTime, endTime);
result.forEach(r ->{
RauthorCount o = rauthCountDao.queryByParams(Long.valueOf(r.get("user_id").toString()), r.get("date6").toString().replace("-",""), r.get("author").toString());
if(o==null){
o = new RauthorCount();
o.setUser_id(Long.valueOf(r.get("user_id").toString()));
o.setRegion_id(r.get("region_code")==null?null:Long.valueOf(r.get("region_code").toString()));
o.setDate6(r.get("date6").toString().replace("-",""));
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setAuthor(toString(r.get("author")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rauthCountDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rauthCountDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRreadComp(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRreadComp(beginTime, endTime);
result.forEach(r ->{
RreadComp o = rreadCompDao.queryByParams(Long.valueOf(r.get("user_id").toString()), r.get("date6").toString().replace("-",""), r.get("book_type").toString());
if(o==null){
o = new RreadComp();
o.setUser_id(Long.valueOf(r.get("user_id").toString()));
o.setDate6(r.get("date6").toString().replace("-",""));
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setUser_name(toString(r.get("real_name")));
o.setType(r.get("book_type").toString());
o.setCc(Long.valueOf(r.get("cc").toString()));
rreadCompDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rreadCompDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRpublishingCount(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRpublishingCount(beginTime, endTime);
result.forEach(r ->{
RpublishingCount o = rpublishingCountDao.queryByParams(Long.valueOf(r.get("user_id").toString()), r.get("date6").toString().replace("-",""), r.get("pub_name").toString());
if(o==null){
o = new RpublishingCount();
o.setUser_id(Long.valueOf(r.get("user_id").toString()));
o.setDate6(r.get("date6").toString().replace("-",""));
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setPublishing(r.get("pub_name").toString());
o.setCc(Long.valueOf(r.get("cc").toString()));
rpublishingCountDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rpublishingCountDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRtypeCount(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRtypeCount(beginTime, endTime);
result.forEach(r ->{
if(clcType.containsKey(r.get("type").toString())){
RtypeCount o = rtypeCountDao.queryByParams(Long.valueOf(r.get("user_id").toString()), r.get("date6").toString().replace("-",""), r.get("type").toString());
if(o==null){
o = new RtypeCount();
o.setUser_id(Long.valueOf(r.get("user_id").toString()));
o.setDate6(r.get("date6").toString().replace("-",""));
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setType(r.get("type").toString());
o.setCc(Long.valueOf(r.get("cc").toString()));
o.setRegion_id(r.get("region_code")==null?null:Long.valueOf(r.get("region_code").toString()));
rtypeCountDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rtypeCountDao.replace(o);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookRate(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookRate(beginTime, endTime);
result.forEach(r ->{
if(clcType.containsKey(r.get("clc_code").toString())){
RbookRate o = rbookRateDao.queryByParams(r.get("clc_code").toString(), r.get("year").toString());
if(o==null){
o = new RbookRate();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setZt_id(r.get("clc_code").toString());
o.setZt_name(clcType.get(r.get("clc_code").toString()).toString());
o.setYear(r.get("year").toString());
o.setUsed_count(Long.valueOf(r.get("cc").toString()));
rbookRateDao.insert(o);
} else {
o.setUsed_count(o.getUsed_count() + Long.valueOf(r.get("cc").toString()));
rbookRateDao.replace(o);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulZttrend(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulZttrend(beginTime, endTime);
result.forEach(r ->{
if(clcType.containsKey(r.get("clc_code").toString())){
RmulZttrend o = rmulZttrendDao.queryByParams(r.get("clc_code").toString(), r.get("year").toString(), Long.valueOf(r.get("mon").toString()));
if(o==null){
o = new RmulZttrend();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setZt_id(r.get("clc_code").toString());
o.setZt_name(clcType.get(r.get("clc_code").toString()).toString());
o.setYear(r.get("year").toString());
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulZttrendDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulZttrendDao.replace(o);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulPub(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulPub(beginTime, endTime);
result.forEach(r ->{
RmulPub o = rmulPubDao.queryByParams(Long.valueOf(r.get("pub_code").toString()), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RmulPub();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setDate6(r.get("date6").toString().replace("-",""));
o.setPub_id(Long.valueOf(r.get("pub_code").toString()));
o.setPub_name(toString(r.get("pub_name")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulPubDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulPubDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulPubtrend(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulPubtrend(beginTime, endTime);
result.forEach(r ->{
RmulPubtrend o = rmulPubtrendDao.queryByParams(Long.valueOf(r.get("pub_code").toString()), r.get("year").toString(), Long.valueOf(r.get("mon").toString()));
if(o==null){
o = new RmulPubtrend();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setYear(r.get("year").toString());
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setPub_id(Long.valueOf(r.get("pub_code").toString()));
o.setPub_name(toString(r.get("pub_name")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulPubtrendDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulPubtrendDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookStar(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookStar(beginTime, endTime);
result.forEach(r ->{
RbookStar o = rbookStarDao.queryByParams(Long.valueOf(r.get("user_id").toString()), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RbookStar();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setStudent_id(Long.valueOf(r.get("user_id").toString()));
o.setStudent_name(toString(r.get("real_name").toString()));
o.setRegion_id(r.get("region_code")==null?null:Long.valueOf(r.get("region_code").toString()));
if(o.getRegion_id()!=null) {
o.setRegion_name(toString(areaType.get(r.get("region_code").toString())));
}
o.setDate6(r.get("date6").toString().replace("-",""));
o.setCc(Long.valueOf(r.get("cc").toString()));
rbookStarDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rbookStarDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookBooks(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookBooks(beginTime, endTime);
result.forEach(r ->{
RbookBooks o = rbookBooksDao.queryByParams(Long.valueOf(r.get("school_id").toString()), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RbookBooks();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setSchool_id(Long.valueOf(r.get("school_id").toString()));
o.setSchool_name(toString(r.get("school_name")));
o.setRegion_id(r.get("region_code")==null?null:Long.valueOf(r.get("region_code").toString()));
o.setRegion_name(r.get("region_code")==null?null:toString(areaType.get(r.get("region_code").toString())));
o.setDate6(r.get("date6").toString().replace("-",""));
o.setCc(Long.valueOf(r.get("cc").toString()));
rbookBooksDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rbookBooksDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookYtrend(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookYtrend(beginTime, endTime);
result.forEach(r ->{
RbookYtrend o = rbookYtrendDao.queryByParams(Long.valueOf(r.get("region_code").toString()), r.get("year").toString());
if(o==null){
o = new RbookYtrend();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setRegion_id(Long.valueOf(r.get("region_code").toString()));
o.setRegion_name(toString(areaType.get(r.get("region_code").toString())));
o.setYear(r.get("year").toString());
o.setCc(Long.valueOf(r.get("cc").toString()));
rbookYtrendDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rbookYtrendDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookMtrend(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookMtrend(beginTime, endTime);
result.forEach(r ->{
RbookMtrend o = rbookMtrendDao.queryByParams(Long.valueOf(r.get("region_code").toString()) ,Long.valueOf(r.get("grade_code").toString())
, r.get("year").toString(), Long.valueOf(r.get("mon").toString()));
if(o==null){
o = new RbookMtrend();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setRegion_id(Long.valueOf(r.get("region_code").toString()));
o.setRegion_name(toString(areaType.get(r.get("region_code").toString())));
o.setGrade_id(Long.valueOf(r.get("grade_code").toString()));
o.setGrade_name(toString(gradeType.get(r.get("grade_code").toString())));
o.setYear(r.get("year").toString());
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setCc(Long.valueOf(r.get("cc").toString()));
rbookMtrendDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rbookMtrendDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookComp(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookComp(beginTime, endTime);
result.forEach(r ->{
RbookComp o = rbookCompDao.queryByParams(r.get("book_type").toString(), r.get("year").toString(), Long.valueOf(r.get("mon").toString()));
if(o==null){
o = new RbookComp();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setBook_type(toString(r.get("book_type")));
o.setYear(r.get("year").toString());
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setCc(new BigDecimal(r.get("cc").toString()).setScale(0, BigDecimal.ROUND_HALF_UP).longValue());
rbookCompDao.insert(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRcostTrend(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRcostTrend(beginTime, endTime);
result.forEach(r ->{
RcostTrend o = rcostTrendDao.queryByParams(r.get("year").toString());
if(o==null){
o = new RcostTrend();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setYear(r.get("year").toString());
o.setCc(Long.valueOf(r.get("cc").toString()));
rcostTrendDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rcostTrendDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRcostSex(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRcostSex(beginTime, endTime);
result.forEach(r ->{
RcostSex o = rcostSexDao.queryByParams(r.get("grade_code").toString(), Long.valueOf(r.get("age").toString()),
r.get("sex_name").toString(), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RcostSex();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setGrade(r.get("grade_code").toString());
o.setAge_id(Long.valueOf(r.get("age").toString()));
o.setAge_name(r.get("age").toString());
o.setSex(r.get("sex_name").toString());
o.setDate6(r.get("date6").toString().replace("-",""));
o.setCc(Long.valueOf(r.get("cc").toString()));
rcostSexDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rcostSexDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRbookHot(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRbookHot(beginTime, endTime);
result.forEach(r ->{
RbookHot o = rbookHotDao.queryByParams(Long.valueOf(r.get("grade_code").toString()), Long.valueOf(r.get("sex_code").toString()),
Long.valueOf(r.get("book_id").toString()), r.get("year").toString());
if(o==null){
o = new RbookHot();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setGrade_id(Long.valueOf(r.get("grade_code").toString()));
o.setGrade_name(toString(gradeType.get(r.get("grade_code").toString())));
o.setSex_id(Long.valueOf(r.get("sex_code").toString()));
o.setSex_name(r.get("sex_name").toString());
o.setBook_id(Long.valueOf(r.get("book_id").toString()));
o.setBook_name(toString(r.get("book_name")));
o.setDate6(toString(r.get("year")));
o.setAuthor(toString(r.get("author")));
o.setPress(toString(r.get("pub_name")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rbookHotDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rbookHotDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulZtreg(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulZtreg(beginTime, endTime);
result.forEach(r ->{
if(clcType.containsKey(r.get("clc_code").toString())){
RmulZtreg o = rmulZtregDao.queryByParams(Long.valueOf(r.get("region_code").toString()), r.get("clc_code").toString(), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RmulZtreg();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setZt_id(r.get("clc_code").toString());
o.setZt_name(clcType.get(r.get("clc_code").toString()).toString());
o.setDate6(r.get("date6").toString().replace("-",""));
o.setRegion_id(Long.valueOf(r.get("region_code").toString()));
o.setRegion_name(toString(areaType.get(r.get("region_code").toString())));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulZtregDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulZtregDao.replace(o);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulZtsex(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulZtsex(beginTime, endTime);
result.forEach(r ->{
if(clcType.containsKey(r.get("clc_code").toString())){
RmulZtsex o = rmulZtsexDao.queryByParams(Long.valueOf(r.get("region_code").toString()),Long.valueOf(r.get("sex_code").toString()),
r.get("clc_code").toString(), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RmulZtsex();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setZt_id(r.get("clc_code").toString());
o.setZt_name(clcType.get(r.get("clc_code").toString()).toString());
o.setDate6(r.get("date6").toString().replace("-",""));
o.setRegion_id(Long.valueOf(r.get("region_code").toString()));
o.setRegion_name(toString(areaType.get(r.get("region_code").toString())));
o.setSex_id(Long.valueOf(r.get("sex_code").toString()));
o.setSex_name(toString(r.get("sex_name")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulZtsexDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulZtsexDao.replace(o);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulZtage(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulZtage(beginTime, endTime);
result.forEach(r ->{
if(clcType.containsKey(r.get("clc_code").toString())){
RmulZtage o = rmulZtageDao.queryByParams(Long.valueOf(r.get("region_code").toString()),Long.valueOf(r.get("age").toString())-2,
r.get("clc_code").toString(), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RmulZtage();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setZt_id(r.get("clc_code").toString());
o.setZt_name(clcType.get(r.get("clc_code").toString()).toString());
o.setDate6(r.get("date6").toString().replace("-",""));
o.setRegion_id(Long.valueOf(r.get("region_code").toString()));
o.setRegion_name(toString(areaType.get(r.get("region_code").toString())));
o.setAge_id(Long.valueOf(r.get("age").toString())-2);
o.setAge_name(toString(r.get("age")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulZtageDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulZtageDao.replace(o);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRmulAuth(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRmulAuth(beginTime, endTime);
result.forEach(r ->{
RmulAuth o = rmulAuthDao.queryByParams(Long.valueOf(r.get("sex_code").toString()),Long.valueOf(r.get("grade_code").toString()),
r.get("author").toString(), r.get("year").toString());
if(o==null){
o = new RmulAuth();
o.setLevel_id(21l);
o.setLevel_type(1);
o.setSrc_type(r.get("client_id").toString().equals(shangtuClientId)?4:null);
o.setSex_id(Long.valueOf(r.get("sex_code").toString()));
o.setSex_name(toString(r.get("sex_name")));
o.setDate6(r.get("year").toString());
o.setGrade_id(Long.valueOf(r.get("grade_code").toString()));
o.setGrade_name(toString(gradeType.get(r.get("grade_code").toString())));
o.setAuthor_id(r.get("author_id")==null?null:Long.valueOf(r.get("author_id").toString()));
o.setAuthor_name(toString(r.get("author")));
o.setCc(Long.valueOf(r.get("cc").toString()));
rmulAuthDao.insert(o);
} else {
o.setCc(o.getCc() + Long.valueOf(r.get("cc").toString()));
rmulAuthDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
public void processRreadQuantity(Date beginTime, Date endTime){
try {
List<LinkedHashMap> result = readingBaseInfoDao.queryRreadQuantity(beginTime, endTime);
result.forEach(r ->{
RreadQuantity o = rreadQuantityDao.queryByParams(Long.valueOf(r.get("user_id").toString()), r.get("date6").toString().replace("-",""));
if(o==null){
o = new RreadQuantity();
o.setUser_id(Long.valueOf(r.get("user_id").toString()));
o.setDate6(r.get("date6").toString().replace("-",""));
o.setMonth(Long.valueOf(r.get("mon").toString()));
o.setRegion_id(r.get("region_code")==null?null:Long.valueOf(r.get("region_code").toString()));
o.setRead_count(Long.valueOf(r.get("cc").toString()));
rreadQuantityDao.insert(o);
} else {
o.setRead_count(o.getRead_count() + Long.valueOf(r.get("cc").toString()));
rreadQuantityDao.replace(o);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
private String toString(Object ob){
return ob==null?null:ob.toString();
}
private Date addTwentySec(Date date){
return new Date(date.getTime() + 4000);
}
private Date addOneMilli(Date date){
return new Date(date.getTime() + 1);
}
private Date addOneHundredSec(Date date){
return new Date(date.getTime() + 20000);
}
}
package com.chineseall.djgdata.service.impl;
import com.chineseall.djgdata.dao.ReadingDataDao;
import com.chineseall.djgdata.model.ReadingData;
import com.chineseall.djgdata.service.ReadingDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.UUID;
@Service
public class ReadingDataServiceImpl implements ReadingDataService {
@Autowired
private ReadingDataDao readingDataDao;
@Override
public ReadingData getById(String id) {
return readingDataDao.load(id);
}
@Override
public void save(ReadingData readingData) {
if(readingData.getId() != null){
readingDataDao.replace(readingData);
}
}
}
server:
port: 9700
context-path: /authcenter
spring:
application:
name: eden-authcenter-agent
mvc:
static-path-pattern: /static/**
thymeleaf:
cache: false
prefix: classpath:/templates/
suffix: .html
mode: LEGACYHTML5
encoding: UTF-8
enabled: true
content-type: text/html
jackson:
property-naming-strategy: CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES
default-property-inclusion: non_null
serialization: true
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
http:
multipart:
max-file-size: 200MB
max-request-size: 300MB
oauthclient:
clients:
- clientName: 上海数字教材
clientId: szjcClentId
clientSecret: szjcClientSecret
- clientName: 上图
clientId: shangtuClentId
clientSecret: shangtuClientSecret
{
"mongo": [
{
"connectionName": "mongo",
"host": "192.168.1.177",
"port": 27017,
"replicaSet": "192.168.1.177:27017",
"maxConnectionsPerHost": 3000,
"threadsAllowedToBlockForConnectionMultiplier": 10,
"authentication": true,
"connectTimeout": 10000,
"password": "123456",
"userName": "xapiUser",
"dbName": "xapi"
}
],
"mysql": [
{
"name": "main",
"masterConfig": {
"autoCommit": true,
"connectionTimeout": 30000,
"driverClass": "com.mysql.jdbc.Driver",
"idleTimeout": 600000,
"jdbcUrl": "jdbc:mysql://192.168.1.177:3306/avmdb?characterEncoding=utf8",
"maxLifetime": 1800000,
"maximumPoolSize": 20,
"minimumIdle": 4,
"password": "chineseall",
"username": "root"
}
}
]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment