NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.ge.service.playWeb.group.log.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ge.entity.playWeb.group.log.GroupLogWebPo;
import com.ge.mapp.playWeb.log.LogWebMapper;
import com.ge.mapper.playWeb.group.log.GroupLogWebMapper;
import com.ge.service.playWeb.group.log.IGroupLogWebService;

@Service("groupLogWebService")
public class GroupLogWebService implements IGroupLogWebService {

@Autowired
private GroupLogWebMapper groupLogWebMapper;

@Autowired
private LogWebMapper logWebMapper;

@Override
public List<GroupLogWebPo> findLogList(Long phone, int months) {

String[] tableName = getTableName(months);
// 查询入网时间
String openDate = groupLogWebMapper.findOpenDate(phone);
if (openDate == null || "".equals(openDate)) { // 如果没有查询到入网时间

return findLogList(months, tableName, phone);
} else { // 查询到了入网时间
// 计算查询到的入网时间与现在相隔几个月
int monthDifference = compareMonth(openDate.substring(0, 6));
if (monthDifference >= months) {
return findLogList(months, tableName, phone);
} else {
return findLogList(monthDifference, tableName, phone);
}
}
}

/**
*
* @param months
* 实际要查询的月份
* @param tableName
* 要查询的月份
* @param phone
* 手机号
* @return
*/
private List<GroupLogWebPo> findLogList(int months, String[] tableName,
Long phone) {
List<GroupLogWebPo> logList = new ArrayList<GroupLogWebPo>();
for (int i = 0; i < tableName.length; i++) {
if (i < tableName.length - months) {
GroupLogWebPo log = new GroupLogWebPo();
log.setYyyyMM(tableName[i].substring(12));
log.setNum(0L);
log.setHasLogged("false");
logList.add(log);
} else {
try {
GroupLogWebPo log = groupLogWebMapper.findLog(tableName[i],
phone);
if (log != null) {
log.setYyyyMM(tableName[i].substring(12));
log.setHasLogged("true");
logList.add(log);
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
GroupLogWebPo log = new GroupLogWebPo();
log.setYyyyMM(tableName[i].substring(12));
log.setNum(0L);
log.setHasLogged("false");
logList.add(log);
}
}
return logList;
}

/**
* @Description 根据当前月份,查询过去几个月的月表表名
* @param months
*/
private String[] getTableName(int months) {
// 获取时间,年月[yyyyMM]格式
SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
String yyyyMM = sf.format(new Date());
String[] tableName = new String[months];

tableName[months - 1] = getLastMonth(yyyyMM);
for (int i = months - 2; i > -1; i--) {
tableName[i] = getLastMonth(tableName[i + 1]);
}
for (int i = 0; i < tableName.length; i++) {
tableName[i] = "log_tb_month" + tableName[i];
}
return tableName;
}

/**
* 根据当月月份,查询过去几个月的月表表名,除了上个月
*/
private String[] getTableNameExceptLastMonth(int months){
// 获取时间,年月[yyyyMM]格式
SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
String yyyyMM = sf.format(new Date());
String[] tableName = new String[months];
tableName[months-1] = getLastMonth(getLastMonth(yyyyMM));
for (int i = months - 2; i > -1; i--) {
tableName[i] = getLastMonth(tableName[i + 1]);
}
for (int i = 0; i < tableName.length; i++) {
tableName[i] = "log_tb_month" + tableName[i];
}
return tableName;
}

/**
* @DESCRIPTION 根据 yyyyMM 格式 获取 上一个月
* @param yyyyMM
*/
private String getLastMonth(String yyyyMM) {
String yyyy = yyyyMM.substring(0, 4);
String MM = yyyyMM.substring(4);
int year = Integer.valueOf(yyyy).intValue();
int month = Integer.valueOf(MM).intValue();
if (month == 1) {
year--;
month = 12;
} else {
month--;
}
return "" + year + (month < 10 ? "0" + month : month);
}

private int compareMonth(String yyyyMM) {
String yyyyStr = yyyyMM.substring(0, 4);
String MMStr = yyyyMM.substring(4, 6);
int yyyy = Integer.valueOf(yyyyStr).intValue();
int MM = Integer.valueOf(MMStr).intValue();

SimpleDateFormat sf = new SimpleDateFormat("yyyyMM");
String yyyyMMNow = sf.format(new Date());
int yyyyNow = Integer.valueOf(yyyyMMNow.substring(0, 4)).intValue();
int MMNow = Integer.valueOf(yyyyMMNow.substring(4)).intValue();

return (yyyyNow - yyyy) * 12 + (MMNow - MM);
}

@Override
public String findOpenDate(Long phone) {
return groupLogWebMapper.findOpenDate(phone);
}

@Override
public boolean isNewUser(Long phone) {
// Long startTime = System.currentTimeMillis();
// 查询入网时间
String openDate = groupLogWebMapper.findOpenDate(phone);
String[] tableNames = null;
if (openDate == null || "".equals(openDate)) {
// 没有获取到入网时间
// 查询过去6个月的登录记录
tableNames = getTableName(6);
} else {
// 查询到了入网时间
// 计算查询到的入网时间与现在相隔几个月
int monthDifference = compareMonth(openDate.substring(0, 6));
if (monthDifference <= 0) {
// 0:当月 、 小于0:数据或者程序错了
// Long endTime = System.currentTimeMillis();
// System.out.println("查询是否是新用户用了"+(endTime-startTime)+"ms");
return true;
}
if(monthDifference >= 6){
tableNames = getTableName(6);
}else{
tableNames = getTableName(monthDifference);
}
}
// int loginStatus = groupLogWebMapper.findLoginStatus(tableNames, phone);
int loginStatus = logWebMapper.findLoginStatus(tableNames, phone);
if(loginStatus > 0){
// Long endTime = System.currentTimeMillis();
// System.out.println("查询是否是新用户用了"+(endTime-startTime)+"ms");
return false;
}else{
// Long endTime = System.currentTimeMillis();
// System.out.println("查询是否是新用户用了"+(endTime-startTime)+"ms");
return true;
}
}

@Override
public boolean isNewUserNoError(Long phone) {
// 查询上个月月表是否生成
String lastMonthTableName = getTableName(1)[0];
// if(lastMonthTableName.equals(groupLogWebMapper.findTableNameByTableName(lastMonthTableName))){
if(lastMonthTableName.equals(logWebMapper.findTableNameByTableName(lastMonthTableName))){
// 上个月月文件存在
return isNewUser(phone);
}

// 查询入网时间
String openDate = groupLogWebMapper.findOpenDate(phone);
String[] tableNames = null;
if (openDate == null || "".equals(openDate)) {
tableNames = getTableNameExceptLastMonth(6);
} else {
int monthDifference = compareMonth(openDate.substring(0, 6));
if (monthDifference <= 0) {
return true;
}
if(monthDifference >= 6){
tableNames = getTableNameExceptLastMonth(6);
}else{
tableNames = getTableNameExceptLastMonth(monthDifference);
}
}
// int loginStatus = groupLogWebMapper.findLoginStatus(tableNames, phone);
int loginStatus = logWebMapper.findLoginStatus(tableNames, phone);
if(loginStatus > 0){
return false;
}else{
return true;
}

}

/**
* 查询上个月月文件是否已经生成
*/
public boolean findLastMonthTable() {
String lastMonthTableName = getTableName(1)[0];
if (lastMonthTableName.equals(logWebMapper.findTableNameByTableName(lastMonthTableName))) {
return true;
}
return false;
}

public static void main(String[] args) {
String[] tableNameArray = new GroupLogWebService().getTableNameExceptLastMonth(10);
for(int i = 0;i<tableNameArray.length;i++){
System.out.println(tableNameArray[i]);
}
}



}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.