Browse Source

feat : 统计相关接口

haihang
whh 3 months ago
parent
commit
34c06045d2
  1. 46
      document/src/main/java/com/haihang/controller/ReportController.java
  2. 9
      document/src/main/java/com/haihang/entity/UserCaseVO.java
  3. 10
      document/src/main/java/com/haihang/mapper/CaseMapper.java
  4. 8
      document/src/main/java/com/haihang/mapper/UserRoleMapper.java
  5. 19
      document/src/main/java/com/haihang/service/ReportService.java
  6. 52
      document/src/main/java/com/haihang/service/impl/ReportServiceImpl.java
  7. 8
      document/src/main/resources/mapper/CaseMapper.xml

46
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);
}
}

9
document/src/main/java/com/haihang/entity/UserCaseVO.java

@ -0,0 +1,9 @@
package com.haihang.entity;
import lombok.Data;
@Data
public class UserCaseVO {
//用户用例大全
}

10
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<Case> pageQuery(CasePageQueryDTO casePageQueryDTO);
@Select("select id from case_table where create_user =#{id}")
List<Integer> queryByUserId(int id);
@Select("select id from case_table where DATE(create_time) = #{date}")
List<Integer> queryByDate(String date);
Integer queryBeforeDateByUser(LocalDate date, int userId);
}

8
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);
}

19
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);
}

52
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<Integer> list = caseMapper.queryByUserId(id);
return Result.ok(list.size());
}
@Override
public Result dayCase(LocalDate date) {
//根据日期筛选出符合当前日期的用例
System.out.println(date.toString());
List<Integer> 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);
}
}

8
document/src/main/resources/mapper/CaseMapper.xml

@ -12,6 +12,14 @@
</select>
<select id="queryBeforeDateByUser" resultType="java.lang.Integer">
select count(id) from case_table
<where>
<if test="date!= null">and create_time &lt; #{date}</if>
and create_user = #{userId}
</where>
</select>
</mapper>

Loading…
Cancel
Save