添加了按照时间段查询工时记录的接口

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-09-01 18:02:27 +08:00
parent 3f8e3f2a39
commit f0d0f473ef
6 changed files with 59 additions and 9 deletions

View File

@ -99,19 +99,22 @@ public class WorkHourRecordController {
/**
* 查询我参与的当前项目的提交的工时记录
* @param projectNumber
* @param map
* @param token
* @return
*/
@GetMapping("/findRecord")
@PostMapping("/findRecord")
@PreAuthorize("hasAnyAuthority('auth_administor','auth_general_user')")
public String findRecord(@RequestParam("projectNumber") String projectNumber,@RequestHeader(value="Authorization") String token){
public String findRecord(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
String projectNumber = (String) map.get("projectNumber");
String startTime = (String) map.get("startTime");
String endTime = (String) map.get("endTime");
// 验证token
String tokenUserName = TokenUtil.getTokenUserName(token);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
List<WorkHourRecord> workHourRecords = workHourRecordService.findRecord(projectNumber, sysUserEntity.getId());
List<WorkHourRecord> workHourRecords = workHourRecordService.findRecord(projectNumber, sysUserEntity.getId(),startTime,endTime);
if(workHourRecords == null || workHourRecords.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该项目的工时记录",locale);
}

View File

@ -5,6 +5,7 @@ import com.xkrs.model.vo.MemberWorkRecordVo;
import com.xkrs.model.vo.OutExcelVo;
import com.xkrs.model.vo.OutMemberVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
@ -17,7 +18,7 @@ import java.util.Map;
* @author XinYi Song
*/
@Component
public interface WorkHourRecordDao extends JpaRepository<WorkHourRecord,Long> {
public interface WorkHourRecordDao extends JpaRepository<WorkHourRecord,Long>, JpaSpecificationExecutor<WorkHourRecord> {
/**
* 查询我参与的

View File

@ -47,9 +47,11 @@ public interface WorkHourRecordService {
* 查询我参与的当前项目的提交的工时记录
* @param projectNumber
* @param userId
* @param startTime
* @param endTime
* @return
*/
List<WorkHourRecord> findRecord(String projectNumber,Integer userId);
List<WorkHourRecord> findRecord(String projectNumber,Integer userId,String startTime, String endTime);
/**
* 修改工时记录

View File

@ -12,6 +12,7 @@ import com.xkrs.model.vo.OutExcelVo;
import com.xkrs.model.vo.OutMemberVo;
import com.xkrs.service.WorkHourRecordService;
import com.xkrs.utils.DateTimeUtil;
import com.xkrs.utils.Query;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.springframework.context.i18n.LocaleContextHolder;
@ -40,6 +41,9 @@ public class WorkHourRecordServiceImpl implements WorkHourRecordService {
@Resource
private SysUserDao sysUserDao;
@Resource
private Query query;
/**
* 提交工时记录
* @param workRecordQo
@ -101,11 +105,13 @@ public class WorkHourRecordServiceImpl implements WorkHourRecordService {
* 查询我参与的当前项目的提交的工时记录
* @param projectNumber
* @param userId
* @param startTime
* @param endTime
* @return
*/
@Override
public List<WorkHourRecord> findRecord(String projectNumber, Integer userId) {
return workHourRecordDao.findRecord(projectNumber,userId);
public List<WorkHourRecord> findRecord(String projectNumber, Integer userId, String startTime, String endTime) {
return query.selectWorkRecord(projectNumber,userId,startTime,endTime);
}
/**

View File

@ -1,7 +1,9 @@
package com.xkrs.utils;
import com.xkrs.dao.ProjectOverviewDao;
import com.xkrs.dao.WorkHourRecordDao;
import com.xkrs.model.entity.ProjectOverview;
import com.xkrs.model.entity.WorkHourRecord;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
@ -23,6 +25,9 @@ public class Query {
@Resource
private ProjectOverviewDao projectOverviewDao;
@Resource
private WorkHourRecordDao workHourRecordDao;
/**
* 动态多条件查询项目信息
* @param
@ -47,4 +52,37 @@ public class Query {
}
/**
* 查询工时记录
* @param projectNumber
* @param userId
* @param startTime
* @param endTime
* @return
*/
public List<WorkHourRecord> selectWorkRecord(String projectNumber, Integer userId, String startTime, String endTime) {
Specification<WorkHourRecord> specification = new Specification<WorkHourRecord>() {
@Override
public Predicate toPredicate(Root<WorkHourRecord> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<>();
if (projectNumber != null && !"".equals(projectNumber)) {
list.add(criteriaBuilder.equal(root.get("projectNumber").as(String.class), projectNumber));
}
if (userId != null && !"".equals(userId)) {
list.add(criteriaBuilder.equal(root.get("userId").as(Integer.class), userId));
}
if(startTime != null && !"".equals(startTime)){
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("submitTime").as(String.class), startTime));
}
if(endTime != null && !"".equals(endTime)){
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("submitTime").as(String.class), endTime));
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return workHourRecordDao.findAll(specification);
}
}

View File

@ -29,7 +29,7 @@ spring.datasource.hikari.validation-timeout = 3000
## Spring Data JPA 配置
spring.jpa.database = POSTGRESQL
spring.jpa.database-platform = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql = true
spring.jpa.show-sql = false
# 指定 ddl mode (none, validate, create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# 命名策略