|
|
|
@ -1,11 +1,18 @@ |
|
|
|
|
package com.daqing.financial.hrauth.service.impl; |
|
|
|
|
|
|
|
|
|
import com.daqing.financial.hrauth.model.AccessRecordsObjRes; |
|
|
|
|
import com.daqing.financial.hrauth.model.HrmsAccessRecordsLog; |
|
|
|
|
import com.daqing.financial.hrauth.dao.HrmsAccessRecordsLogMapper; |
|
|
|
|
import com.daqing.financial.hrauth.service.IHrmsAccessRecordsLogService; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import io.swagger.models.auth.In; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* <p> |
|
|
|
|
* 访问记录表 服务实现类 |
|
|
|
@ -17,4 +24,215 @@ import org.springframework.stereotype.Service; |
|
|
|
|
@Service |
|
|
|
|
public class HrmsAccessRecordsLogServiceImpl extends ServiceImpl<HrmsAccessRecordsLogMapper, HrmsAccessRecordsLog> implements IHrmsAccessRecordsLogService { |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private HrmsAccessRecordsLogMapper hrmsAccessRecordsLogMapper; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<HrmsAccessRecordsLog> queryAccessRecords() { |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
String dateTime=sdf.format(new Date()); |
|
|
|
|
//显示当天前五条最新数据
|
|
|
|
|
List<HrmsAccessRecordsLog> list = hrmsAccessRecordsLogMapper.queryAccessRecords(dateTime); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map queryVisitNum() { |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
String dateTime=sdf.format(new Date()); |
|
|
|
|
//查询当天PC端登录和小程序登录总条数
|
|
|
|
|
int countPC = hrmsAccessRecordsLogMapper.queryAccessCountPC(dateTime); |
|
|
|
|
int countAPP = hrmsAccessRecordsLogMapper.queryAccessCountAPP(dateTime); |
|
|
|
|
int countSum = countPC+countAPP; |
|
|
|
|
Map<String,Integer> map = new HashMap<String,Integer>(); |
|
|
|
|
map.put("countPC",countPC); |
|
|
|
|
map.put("countAPP",countAPP); |
|
|
|
|
map.put("countSum",countSum); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map queryLoginNum() { |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
String dateTime=sdf.format(new Date()); |
|
|
|
|
//今日登录用户总数
|
|
|
|
|
int userCount = hrmsAccessRecordsLogMapper.queryUserCount(dateTime); |
|
|
|
|
Map<String,Integer> map = new HashMap<String,Integer>(); |
|
|
|
|
map.put("userCount",userCount); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map queryLoginOnline() { |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
String dateTime=sdf.format(new Date()); |
|
|
|
|
//今日登录用户时间点
|
|
|
|
|
List<String> timeList = hrmsAccessRecordsLogMapper.queryLoginTime(dateTime); |
|
|
|
|
System.out.println("timeList=============="+timeList); |
|
|
|
|
//timeList==============[11, 12, 14, 15, 16, 17]
|
|
|
|
|
//今日登录用户不同时间点登录总数
|
|
|
|
|
List<Integer> approvalList = hrmsAccessRecordsLogMapper.queryLoginSum(dateTime); |
|
|
|
|
System.out.println("approvalList================"+approvalList); |
|
|
|
|
//approvalList================[1, 1, 2, 3, 1, 1]
|
|
|
|
|
List<AccessRecordsObjRes> loginObj = hrmsAccessRecordsLogMapper.queryLoginObj(dateTime); |
|
|
|
|
System.out.println("loginObj================"+loginObj); |
|
|
|
|
//loginObj================[AccessRecordsObjRes(loginTime=11:00, loginSum=1), AccessRecordsObjRes(loginTime=12:00, loginSum=1), AccessRecordsObjRes(loginTime=14:00, loginSum=1), AccessRecordsObjRes(loginTime=15:00, loginSum=3), AccessRecordsObjRes(loginTime=16:00, loginSum=2)]
|
|
|
|
|
|
|
|
|
|
List list = new ArrayList(); |
|
|
|
|
for (String str:timeList) { |
|
|
|
|
//如果第一个为奇数,就取它的偶数时间点
|
|
|
|
|
if(Integer.parseInt(str)%2!=0){ |
|
|
|
|
int a = Integer.parseInt(str)-1; |
|
|
|
|
list.add(String.valueOf(a)); |
|
|
|
|
}else{ |
|
|
|
|
list.add(str); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
System.out.println("timeList2=============="+list); |
|
|
|
|
//timeList2==============[10, 12, 14, 14, 16, 16]
|
|
|
|
|
Map<Integer,String> same = same(list); |
|
|
|
|
System.out.println("same==============="+same); |
|
|
|
|
//14 重复,行: 3,4
|
|
|
|
|
//16 重复,行: 5,6
|
|
|
|
|
List<String> strList = new ArrayList<>(); |
|
|
|
|
Iterator<Integer> iter = same.keySet().iterator(); |
|
|
|
|
while(iter.hasNext()){ |
|
|
|
|
Integer key=iter.next(); |
|
|
|
|
String value = same.get(key); |
|
|
|
|
System.out.println(key+" "+value); |
|
|
|
|
strList.add(value); |
|
|
|
|
} |
|
|
|
|
Collections.sort(strList); |
|
|
|
|
System.out.println("strListSort============="+strList); |
|
|
|
|
//strList=============[8,9, 2,3, 4,5, 6,7]
|
|
|
|
|
//approvalList================[2, 1, 2, 12, 2, 3, 1, 1, 1, 1]
|
|
|
|
|
//[10, 12, 14, 16, 18, 22]
|
|
|
|
|
List list2 = new ArrayList(); |
|
|
|
|
|
|
|
|
|
//遍历每一个approvalList,取出它们对应的下标
|
|
|
|
|
outer:for(int i=0;i<approvalList.size();i++){ |
|
|
|
|
for(int j=0;j<strList.size();j++){ |
|
|
|
|
if(strList.get(j).contains(String.valueOf(i))){ |
|
|
|
|
String s = strList.get(j); |
|
|
|
|
String[] split = s.split(","); |
|
|
|
|
Integer sum =0; |
|
|
|
|
for(String str:split){ |
|
|
|
|
Integer a =approvalList.get(Integer.parseInt(str)); |
|
|
|
|
sum = sum+a; |
|
|
|
|
} |
|
|
|
|
list2.add(sum); |
|
|
|
|
int length = split.length; |
|
|
|
|
if(i+length < approvalList.size()){ |
|
|
|
|
i=i+length; |
|
|
|
|
continue; |
|
|
|
|
}else{//结束所有循环
|
|
|
|
|
break outer; |
|
|
|
|
} |
|
|
|
|
}else{//不包含情况下
|
|
|
|
|
//list2.add(approvalList.get(i));
|
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
list2.add(approvalList.get(i)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
System.out.println("list2=============="+list2); |
|
|
|
|
|
|
|
|
|
//去重
|
|
|
|
|
List distinctList=(List) list.stream().distinct().collect(Collectors.toList()); |
|
|
|
|
System.out.println(distinctList); |
|
|
|
|
//[10, 12, 14, 16]
|
|
|
|
|
|
|
|
|
|
Map<String, List> map = new HashMap<>(); |
|
|
|
|
map.put("timeList",distinctList); |
|
|
|
|
map.put("numList",list2); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//查找list中的重复数据,并得到重复数据索引位置
|
|
|
|
|
public static Map same(List<String> list) { |
|
|
|
|
Map<Integer, String> map = new HashMap<Integer, String>(); |
|
|
|
|
Map map2 = new HashMap(); |
|
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
|
Integer key = Integer.parseInt(list.get(i)); |
|
|
|
|
String old = map.get(key); |
|
|
|
|
if (old != null) { |
|
|
|
|
map.put(key, old + "," + (i)); |
|
|
|
|
} else { |
|
|
|
|
map.put(key, "" + (i)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Iterator<Integer> it = map.keySet().iterator(); |
|
|
|
|
while (it.hasNext()) { |
|
|
|
|
Integer key = it.next(); |
|
|
|
|
String value = map.get(key); |
|
|
|
|
if (value.indexOf(",") != -1) { |
|
|
|
|
System.out.println(key + " 重复,行: " + value); |
|
|
|
|
map2.put(key,value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return map2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Map queryLoginOnline2() { |
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
String dateTime=sdf.format(new Date()); |
|
|
|
|
|
|
|
|
|
List<AccessRecordsObjRes> accessList = hrmsAccessRecordsLogMapper.queryLoginObj(dateTime); |
|
|
|
|
System.out.println("accessList=============="+accessList); |
|
|
|
|
//获取当前时间点小时
|
|
|
|
|
SimpleDateFormat sdf2 = new SimpleDateFormat("HH"); |
|
|
|
|
String hour=sdf2.format(new Date()); |
|
|
|
|
int dayHour = Integer.parseInt(hour); |
|
|
|
|
Map map = new HashMap(); |
|
|
|
|
List list = new ArrayList(); |
|
|
|
|
List list2 = new ArrayList(); |
|
|
|
|
//首先通过for循环遍历所有的偶数
|
|
|
|
|
for(int i=0;i<dayHour;i=i+2){ |
|
|
|
|
//通过stream.filter()过滤时间段属性,access即为0对应的0->1时间段以及对应登录人数,或者2对应的2->3时间段以及对应的登录人数
|
|
|
|
|
String s1 = frontCompWithZore(2, i); |
|
|
|
|
String s2 = frontCompWithZore(2, i+1); |
|
|
|
|
|
|
|
|
|
List<AccessRecordsObjRes> access = accessList.stream() |
|
|
|
|
.filter(s->s.getLoginTime().equals(s1) || s.getLoginTime().equals(s2)) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
System.out.println("access==========="+access); |
|
|
|
|
//获取对应的偶数时间段以及对应的登录用户数
|
|
|
|
|
String loginTime=null; |
|
|
|
|
for (AccessRecordsObjRes res:access) { |
|
|
|
|
loginTime = s1; |
|
|
|
|
Integer loginSum = res.getLoginSum(); |
|
|
|
|
res.setLoginSum(loginSum); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
int sum = access.stream().mapToInt(AccessRecordsObjRes::getLoginSum).sum(); |
|
|
|
|
if(sum==0){ |
|
|
|
|
loginTime=s1; |
|
|
|
|
} |
|
|
|
|
list.add(loginTime); |
|
|
|
|
list2.add(sum); |
|
|
|
|
} |
|
|
|
|
map.put("loginTime",list); |
|
|
|
|
map.put("loginSum",list2); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将元数据前补零,补后的总长度为指定的长度,以字符串的形式返回 |
|
|
|
|
* 重组后的数据 |
|
|
|
|
*/ |
|
|
|
|
public static String frontCompWithZore(int formatLength,int formatNumber) { |
|
|
|
|
/** |
|
|
|
|
* 0 指前面补充零 |
|
|
|
|
* formatLength 字符总长度为 formatLength |
|
|
|
|
* inputNumber 格式化数字 |
|
|
|
|
* d 代表为正数。 |
|
|
|
|
*/ |
|
|
|
|
String newString = String.format("%0" + formatLength + "d", formatNumber); |
|
|
|
|
return newString; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|