From 34c06045d2033c264c7d1e1098986a5d68e01390 Mon Sep 17 00:00:00 2001 From: whh <2846845743@qq.com> Date: Fri, 27 Sep 2024 18:08:30 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20=E7=BB=9F=E8=AE=A1=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haihang/controller/ReportController.java | 46 ++++++++++++++++ .../java/com/haihang/entity/UserCaseVO.java | 9 ++++ .../java/com/haihang/mapper/CaseMapper.java | 10 ++++ .../com/haihang/mapper/UserRoleMapper.java | 8 +-- .../com/haihang/service/ReportService.java | 19 +++++++ .../service/impl/ReportServiceImpl.java | 52 +++++++++++++++++++ .../src/main/resources/mapper/CaseMapper.xml | 8 +++ 7 files changed, 148 insertions(+), 4 deletions(-) create mode 100644 document/src/main/java/com/haihang/controller/ReportController.java create mode 100644 document/src/main/java/com/haihang/entity/UserCaseVO.java create mode 100644 document/src/main/java/com/haihang/service/ReportService.java create mode 100644 document/src/main/java/com/haihang/service/impl/ReportServiceImpl.java diff --git a/document/src/main/java/com/haihang/controller/ReportController.java b/document/src/main/java/com/haihang/controller/ReportController.java new file mode 100644 index 0000000..305f2ad --- /dev/null +++ b/document/src/main/java/com/haihang/controller/ReportController.java @@ -0,0 +1,46 @@ +package com.haihang.controller; + +import com.haihang.service.ReportService; +import com.haihang.utils.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDate; +import java.util.Date; + +@RequestMapping("/report") +@RestController +public class ReportController { + + @Autowired + private ReportService reportService; + + @GetMapping("/{id}") + public Result userCases(@PathVariable Integer id) { + //根据用户id统计用户创建的用例数量 + return reportService.userCases(id); + } + + @GetMapping("/dayCase") + public Result dayCase(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date) { + + return reportService.dayCase(date); + } + + @GetMapping("/beforeDayUserCase") + public Result beforeDayUserCase(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date,Integer userId) { +// 3. 统计到指定日期,每个用户的用例数 + return reportService.beforeDayUserCase(date,userId); + } + + @GetMapping("/userAndRole") + public Result userAndRole(Integer roleId) { + + + return reportService.countUserByRoleId(roleId); + } +} diff --git a/document/src/main/java/com/haihang/entity/UserCaseVO.java b/document/src/main/java/com/haihang/entity/UserCaseVO.java new file mode 100644 index 0000000..e529069 --- /dev/null +++ b/document/src/main/java/com/haihang/entity/UserCaseVO.java @@ -0,0 +1,9 @@ +package com.haihang.entity; + +import lombok.Data; + +@Data +public class UserCaseVO { + //用户用例大全 + +} diff --git a/document/src/main/java/com/haihang/mapper/CaseMapper.java b/document/src/main/java/com/haihang/mapper/CaseMapper.java index bea2b50..32366f3 100644 --- a/document/src/main/java/com/haihang/mapper/CaseMapper.java +++ b/document/src/main/java/com/haihang/mapper/CaseMapper.java @@ -5,6 +5,7 @@ import com.haihang.entity.Case; import com.haihang.entity.CasePageQueryDTO; import org.apache.ibatis.annotations.*; +import java.time.LocalDate; import java.util.List; @Mapper @@ -34,4 +35,13 @@ public interface CaseMapper { void updateIsLeaf(int i, int parentId); Page pageQuery(CasePageQueryDTO casePageQueryDTO); + + @Select("select id from case_table where create_user =#{id}") + List queryByUserId(int id); + + @Select("select id from case_table where DATE(create_time) = #{date}") + List queryByDate(String date); + + + Integer queryBeforeDateByUser(LocalDate date, int userId); } diff --git a/document/src/main/java/com/haihang/mapper/UserRoleMapper.java b/document/src/main/java/com/haihang/mapper/UserRoleMapper.java index 498ab4b..1e6b8da 100644 --- a/document/src/main/java/com/haihang/mapper/UserRoleMapper.java +++ b/document/src/main/java/com/haihang/mapper/UserRoleMapper.java @@ -1,10 +1,7 @@ package com.haihang.mapper; import com.haihang.entity.UserDTO; -import org.apache.ibatis.annotations.Delete; -import org.apache.ibatis.annotations.Insert; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Update; +import org.apache.ibatis.annotations.*; @Mapper public interface UserRoleMapper { @@ -22,4 +19,7 @@ public interface UserRoleMapper { @Update("update user_role_relation " + "set ROLE_ID = #{roleId} where USER_ID =#{id}") void updateRoleIdByUserId(UserDTO userDTO); + + @Select("select count(id) from user_role_relation where ROLE_ID =#{roleId}") + Integer CountByRoleId(Integer roleId); } diff --git a/document/src/main/java/com/haihang/service/ReportService.java b/document/src/main/java/com/haihang/service/ReportService.java new file mode 100644 index 0000000..68ffb92 --- /dev/null +++ b/document/src/main/java/com/haihang/service/ReportService.java @@ -0,0 +1,19 @@ +package com.haihang.service; + + +import com.haihang.utils.Result; + +import java.time.LocalDate; +import java.util.Date; + +public interface ReportService { + + + Result userCases(int id); + + Result dayCase(LocalDate date); + + Result beforeDayUserCase(LocalDate date, int userId); + + Result countUserByRoleId(Integer roleId); +} diff --git a/document/src/main/java/com/haihang/service/impl/ReportServiceImpl.java b/document/src/main/java/com/haihang/service/impl/ReportServiceImpl.java new file mode 100644 index 0000000..177b434 --- /dev/null +++ b/document/src/main/java/com/haihang/service/impl/ReportServiceImpl.java @@ -0,0 +1,52 @@ +package com.haihang.service.impl; + +import com.haihang.mapper.CaseMapper; +import com.haihang.mapper.UserRoleMapper; +import com.haihang.service.ReportService; +import com.haihang.utils.Result; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.LocalDate; +import java.util.Date; +import java.util.List; + +@Service +public class ReportServiceImpl implements ReportService { + + @Autowired + private CaseMapper caseMapper; + + @Autowired + private UserRoleMapper userRoleMapper; + + + @Override + public Result userCases(int id) { + List list = caseMapper.queryByUserId(id); + return Result.ok(list.size()); + + } + + @Override + public Result dayCase(LocalDate date) { + //根据日期筛选出符合当前日期的用例 + System.out.println(date.toString()); + List lis = caseMapper.queryByDate(date.toString()); + return Result.ok(lis.size()); + } + + @Override + public Result beforeDayUserCase(LocalDate date, int userId) { + Integer lis = caseMapper.queryBeforeDateByUser(date,userId); + return Result.ok(lis); + } + + @Override + public Result countUserByRoleId(Integer roleId) { + //根据角色id查询角色关联用户数 + //直接查中间表就完了 + Integer count = userRoleMapper.CountByRoleId(roleId); + return Result.ok(count); + } +} diff --git a/document/src/main/resources/mapper/CaseMapper.xml b/document/src/main/resources/mapper/CaseMapper.xml index a284fb6..cc38ff0 100644 --- a/document/src/main/resources/mapper/CaseMapper.xml +++ b/document/src/main/resources/mapper/CaseMapper.xml @@ -12,6 +12,14 @@ + +