diff --git a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/controller/DgAuditProcessController.java b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/controller/DgAuditProcessController.java index 1fde595c..fe33eecd 100644 --- a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/controller/DgAuditProcessController.java +++ b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/controller/DgAuditProcessController.java @@ -7,6 +7,7 @@ import com.daqing.financial.guarantee.model.response.ApprovalNum; import com.daqing.financial.guarantee.model.response.TodayApprovalRecordResponse; import com.daqing.financial.guarantee.service.IDgAuditProcessService; import com.daqing.financial.guarantee.util.R; +import com.daqing.financial.guarantee.util.TaskNodeUtil; import com.daqing.framework.domain.guarantee.DgAuditProcess; import com.daqing.framework.domain.guarantee.po.ProcessPO; import com.daqing.framework.model.response.ResponseResult; @@ -82,7 +83,7 @@ public class DgAuditProcessController { return ResponseResult.SUCCESS(processPO); } - @ApiOperation(value = "今日审批记录") + @ApiOperation(value = "今日审批记录",response = TodayApprovalRecordResponse.class) @GetMapping("todayApprovalRecord") public R nowadaysAuditProcess(){ List approvalRecords = auditProcessService.todayApprovalRecord(); @@ -90,6 +91,11 @@ public class DgAuditProcessController { //统计状态个数 approvalRecords.forEach(todayApprovalRecordResponse -> { if (todayApprovalRecordResponse.getStatus()!=null){ + String taskNode = todayApprovalRecordResponse.getTaskNode(); + if (taskNode!=null){ + String converter = TaskNodeUtil.converter(taskNode); + todayApprovalRecordResponse.setTaskNode(converter); + } switch (todayApprovalRecordResponse.getStatus()){ case "0": approvalNum.setInitiateNum(approvalNum.getInitiateNum()+1); diff --git a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/model/response/TodayApprovalRecordResponse.java b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/model/response/TodayApprovalRecordResponse.java index b0971c07..37c79330 100644 --- a/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/model/response/TodayApprovalRecordResponse.java +++ b/dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/model/response/TodayApprovalRecordResponse.java @@ -1,5 +1,6 @@ package com.daqing.financial.guarantee.model.response; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -30,6 +31,7 @@ public class TodayApprovalRecordResponse { private String taskNode; @ApiModelProperty("处理时间") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date processingTime; @ApiModelProperty("状态") diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplication.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplication.java index f03a6e6c..2e999a5b 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplication.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/DqFinancialHrmsAuthApplication.java @@ -5,10 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; @EnableFeignClients(basePackages = "com.daqing.financial.hrauth.feign") @EnableDiscoveryClient @SpringBootApplication +@EnableScheduling @ComponentScan(basePackages = "com.daqing") public class DqFinancialHrmsAuthApplication { diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/HrmsAccessRecordsLogController.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/HrmsAccessRecordsLogController.java index 517e454a..719d7ceb 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/HrmsAccessRecordsLogController.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/controller/HrmsAccessRecordsLogController.java @@ -1,9 +1,22 @@ package com.daqing.financial.hrauth.controller; +import com.daqing.financial.hrauth.model.HrmsAccessRecordsLog; +import com.daqing.financial.hrauth.service.IHrmsAccessRecordsLogService; +import com.daqing.financial.hrauth.service.impl.HrmsAccessRecordsLogServiceImpl; +import com.daqing.framework.domain.hrms.response.RolePermissionResponse; +import com.daqing.framework.model.response.ResponseResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; /** *

@@ -13,8 +26,62 @@ import org.springframework.stereotype.Controller; * @author Qyq * @since 2021-01-12 */ -@Controller +@RestController @RequestMapping("/hrms-access-records-log") public class HrmsAccessRecordsLogController { + @Autowired + private IHrmsAccessRecordsLogService iHrmsAccessRecordsLogService; + + /** + * 访问记录(显示前五条最新数据),定时任务-每五分钟更新一次 + * @param + * @return + */ + @Scheduled(cron ="0 */5 * * * ?") + @GetMapping("/queryAccessRecords") + public ResponseResult queryAccessRecords() { + List list = iHrmsAccessRecordsLogService.queryAccessRecords(); + return new ResponseResult>().SUCCESS(list); + } + + /** + * 访问次数 + * @return + */ + @Scheduled(cron ="0 */5 * * * ?") + @GetMapping("/queryVisitNum") + public ResponseResult queryVisitNum() { + Map map = iHrmsAccessRecordsLogService.queryVisitNum(); + return new ResponseResult>().SUCCESS(map); + } + + /** + * 今日登录用户总数 + * @return + */ + @GetMapping("/queryLoginNum") + public ResponseResult queryLoginNum() { + Map map = iHrmsAccessRecordsLogService.queryLoginNum(); + return new ResponseResult>().SUCCESS(map); + } + + /** + * 登录用户趋势图 + * @return + */ + @GetMapping("/queryLoginOnline") + public ResponseResult queryLoginOnline() { + Map map = iHrmsAccessRecordsLogService.queryLoginOnline(); + return new ResponseResult>().SUCCESS(map); + } + /** + * 登录用户趋势图 + * @return + */ + @GetMapping("/queryLoginOnline2") + public ResponseResult queryLoginOnline2() { + Map map = iHrmsAccessRecordsLogService.queryLoginOnline2(); + return new ResponseResult>().SUCCESS(map); + } } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/HrmsAccessRecordsLogMapper.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/HrmsAccessRecordsLogMapper.java index b467c85d..ac410be3 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/HrmsAccessRecordsLogMapper.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/dao/HrmsAccessRecordsLogMapper.java @@ -1,8 +1,13 @@ package com.daqing.financial.hrauth.dao; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.daqing.financial.hrauth.model.AccessRecordsObjRes; +import com.daqing.financial.hrauth.model.AccessRecordsRes; import com.daqing.financial.hrauth.model.HrmsAccessRecordsLog; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** *

@@ -14,4 +19,17 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface HrmsAccessRecordsLogMapper extends BaseMapper { + List queryAccessRecords(@Param("loginTime") String dateTime); + + int queryAccessCountPC(@Param("loginTime")String dateTime); + + int queryAccessCountAPP(@Param("loginTime")String dateTime); + + int queryUserCount(@Param("loginTime")String dateTime); + + List queryLoginTime(@Param("loginTime")String dateTime); + + List queryLoginSum(@Param("loginTime")String dateTime); + + List queryLoginObj(@Param("loginTime")String dateTime); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/AccessRecordsObjRes.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/AccessRecordsObjRes.java new file mode 100644 index 00000000..deb00436 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/AccessRecordsObjRes.java @@ -0,0 +1,27 @@ +package com.daqing.financial.hrauth.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + *

+ * 访问记录表 + *

+ * + * @author Qyq + * @since 2021-01-12 + */ +@Data +@TableName("hrms_access_records_log") +public class AccessRecordsObjRes implements Serializable { + + @ApiModelProperty(value = "今日登录用户时间点") + private String loginTime; + @ApiModelProperty(value = "今日登录用户不同时间点登录总数") + private Integer loginSum; + +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/AccessRecordsRes.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/AccessRecordsRes.java new file mode 100644 index 00000000..6200eb07 --- /dev/null +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/AccessRecordsRes.java @@ -0,0 +1,29 @@ +package com.daqing.financial.hrauth.model; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * 访问记录表 + *

+ * + * @author Qyq + * @since 2021-01-12 + */ +@Data +@TableName("hrms_access_records_log") +public class AccessRecordsRes implements Serializable { + + @ApiModelProperty(value = "PC总访问量") + private Integer countPC; + @ApiModelProperty(value = "APP总访问量") + private Integer countAPP; + @ApiModelProperty(value = "总访问量") + private Integer countSum; + + +} diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/HrmsAccessRecordsLog.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/HrmsAccessRecordsLog.java index 9712061b..f8b35a0b 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/HrmsAccessRecordsLog.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/model/HrmsAccessRecordsLog.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import java.io.Serializable; @@ -29,6 +30,8 @@ public class HrmsAccessRecordsLog implements Serializable { @TableId(value = "id", type = IdType.AUTO) private Integer id; + private Integer userId; + /** * 账号 */ @@ -53,5 +56,6 @@ public class HrmsAccessRecordsLog implements Serializable { /** * 登录时间 */ + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date loginTime; } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/IHrmsAccessRecordsLogService.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/IHrmsAccessRecordsLogService.java index f3665a55..a80cf2fd 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/IHrmsAccessRecordsLogService.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/IHrmsAccessRecordsLogService.java @@ -3,6 +3,9 @@ package com.daqing.financial.hrauth.service; import com.daqing.financial.hrauth.model.HrmsAccessRecordsLog; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; +import java.util.Map; + /** *

* 访问记录表 服务类 @@ -13,4 +16,13 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface IHrmsAccessRecordsLogService extends IService { + List queryAccessRecords(); + + Map queryVisitNum(); + + Map queryLoginNum(); + + Map queryLoginOnline(); + + Map queryLoginOnline2(); } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/HrmsAccessRecordsLogServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/HrmsAccessRecordsLogServiceImpl.java index a4e3c4e8..67a34190 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/HrmsAccessRecordsLogServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/HrmsAccessRecordsLogServiceImpl.java @@ -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; + /** *

* 访问记录表 服务实现类 @@ -17,4 +24,215 @@ import org.springframework.stereotype.Service; @Service public class HrmsAccessRecordsLogServiceImpl extends ServiceImpl implements IHrmsAccessRecordsLogService { -} + @Autowired + private HrmsAccessRecordsLogMapper hrmsAccessRecordsLogMapper; + + @Override + public List queryAccessRecords() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String dateTime=sdf.format(new Date()); + //显示当天前五条最新数据 + List 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 map = new HashMap(); + 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 map = new HashMap(); + map.put("userCount",userCount); + return map; + } + + @Override + public Map queryLoginOnline() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String dateTime=sdf.format(new Date()); + //今日登录用户时间点 + List timeList = hrmsAccessRecordsLogMapper.queryLoginTime(dateTime); + System.out.println("timeList=============="+timeList); + //timeList==============[11, 12, 14, 15, 16, 17] + //今日登录用户不同时间点登录总数 + List approvalList = hrmsAccessRecordsLogMapper.queryLoginSum(dateTime); + System.out.println("approvalList================"+approvalList); + //approvalList================[1, 1, 2, 3, 1, 1] + List 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 same = same(list); + System.out.println("same==============="+same); + //14 重复,行: 3,4 + //16 重复,行: 5,6 + List strList = new ArrayList<>(); + Iterator 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 map = new HashMap<>(); + map.put("timeList",distinctList); + map.put("numList",list2); + return map; + } + + //查找list中的重复数据,并得到重复数据索引位置 + public static Map same(List list) { + Map map = new HashMap(); + 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 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 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;i1时间段以及对应登录人数,或者2对应的2->3时间段以及对应的登录人数 + String s1 = frontCompWithZore(2, i); + String s2 = frontCompWithZore(2, i+1); + + List 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; + } + + } diff --git a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java index 2bf6381c..2dec6081 100644 --- a/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java +++ b/dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/service/impl/UserLoginServiceImpl.java @@ -229,8 +229,9 @@ public class UserLoginServiceImpl extends ServiceImpl } recordsLog.setAccount(userEntity.getAccount()); recordsLog.setName(name); - recordsLog.setType(1); + recordsLog.setType(0);//用户端类型:0->PC;1->小程序; recordsLog.setLoginTime(new Date()); + recordsLog.setUserId(userEntity.getId().intValue()); hrmsAccessRecordsLogMapper.insert(recordsLog); //返回用户信息 diff --git a/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/HrmsAccessRecordsLogMapper.xml b/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/HrmsAccessRecordsLogMapper.xml index 829bcc6e..2f44e7fc 100644 --- a/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/HrmsAccessRecordsLogMapper.xml +++ b/dq-financial-hrms-auth/src/main/resources/mapper/hrauth/HrmsAccessRecordsLogMapper.xml @@ -5,6 +5,7 @@ + @@ -12,4 +13,61 @@ + + + + + + + + + + + + + +